Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
asciidoc += '// Use `node scripts/generate-docs-examples.js` to generate the docs examples\n\n'
var code = 'async function run (client) {\n// START\n'
for (var i = 0; i < source.length; i++) {
const { api, query, params, body } = source[i]
const apiArguments = Object.assign({}, params, query, body ? { body } : body)
var serializedApiArguments = Object.keys(apiArguments).length > 0
? JSON.stringify(apiArguments, null, 2)
: ''
code += `const response${getResponsePostfix(i)} = await client.${api.replace(/_([a-z])/g, g => g[1].toUpperCase())}(${serializedApiArguments})
console.log(response${getResponsePostfix(i)})
\n`
}
code += '// END\n}'
const { results } = standard.lintTextSync(code, { fix: true })
code = results[0].output
code = code.slice(code.indexOf('// START\n') + 9, code.indexOf('\n\n// END'))
asciidoc += `[source, js]
----
${dedent(code)}
----
`
return asciidoc
function getResponsePostfix (i) {
if (source.length === 1) return ''
return String(i)
}
}
// Backward compatibility
process.emitWarning('It is recommended to use a Web3 instance instead of Web3Provider')
contract.setProvider(web3)
} else {
throw Error('You should provide a valid web3 instance')
}
}
return contract
}
module.exports = {
${Object.keys(artifacts).map(toFactoryScript).join(',')}
}
`
// It makes the script prettier with standardJS style
const lintResult = standard.lintTextSync(module, { fix: true })
const scriptToWrite = lintResult.results[0].output
// Check does it already exist, if then check the diff and decide to update or not
try {
const legacy = fs.readFileSync(outputPath, 'utf8')
if (legacy === scriptToWrite) {
console.log('truffle-plugin-modularizer: No updates')
resolve()
return
}
} catch (e) {}
// Make directory if it does not exist
fs.mkdir(path.dirname(outputPath), { recursive: true }, (err) => {
if (err) reject(err)
else {
var run = require('./helpers/run')
var put = require('./helpers/put')
var create = require('./helpers/create')
var validate = require('./helpers/fuzzing').validate
tape('autogenerated failing fuzz test', function (t) {
var writesPerReplication = ${JSON.stringify(writeArrays)}.map(b => new Map(b))
create.many(${dbCount}, function (err, dbs, replicateByIndex) {
t.error(err)
run(${writeOps.map(op => op.toString())})
})
})`, { singleQuote: true, semi: false })
var standardized = standard.lintTextSync(source, { fix: true })
console.log(standardized.results[0].output)
console.log('\n')
}
async run (message, args) {
var hrStart = await process.hrtime(this.hrStart)
var lintResult = await standard.lintTextSync(`${args.code}\n`)
var lintLatency = await process.hrtime(hrStart)
var messages = lintResult.results[0].messages.map(m => stripIndents`
**${m.ruleId ? m.ruleId : 'Error'} - (${m.line}:${m.column})**
❯ ${m.message}
`).join('\n')
message.embed({
author: { name: this.client.user.tag, icon_url: this.client.user.displayAvatarURL() },
footer: { text: message.author.tag, icon_url: message.author.displayAvatarURL() },
timestamp: new Date(),
title: `*Linted in ${lintLatency[0] > 0 ? `${lintLatency[0]}s ` : ''}${lintLatency[1] / 1000000}ms.*`,
description: messages ? messages.slice(0, 2000) : '✅ Lint Success!',
color: this.client.getClientColor(message)
})
}
break
case 'cjs':
result = `module.exports = ${value}`
break
case 'browser':
result = `window.${name} = ${value}`
break
default:
result = `${mode ? `var ${mode} =` : ''} ${value}`
}
} else {
result = value
}
}
const lintResult = standard.lintTextSync(result, { fix: true })
return lintResult.results[0].output
} catch (err) {
throw new Error(`Error ${err.message}\n${result}\nraw:\n${js}`)
}
}
if (argument && argument.type === 'AwaitExpression') {
const stmt = j.returnStatement(argument.argument)
stmt.comments = comments
j(path).replaceWith(stmt)
}
if (argument && argument.type === 'ConditionalExpression') {
const { test, consequent, alternate } = argument
const stmt = j.returnStatement(j.conditionalExpression(test,
consequent.type === 'AwaitExpression' ? consequent.argument : consequent,
alternate.type === 'AwaitExpression' ? alternate.argument : alternate))
j(path).replaceWith(stmt)
}
})
const source = root.toSource()
const { results: [{ output }] } = standard.lintTextSync(source, { fix: true })
return output
}