Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFile(filePath, { encoding: 'utf8' }, function (err, data) {
t.error(err, 'read ' + basename + ' file without error ')
var formatted
try {
formatted = fmt(data)
} catch (e) {
t.error(e, 'format ' + basename + ' without error')
}
standard.lintText(formatted, function (err, result) {
t.error(err, 'linting ' + basename + ' should be error free')
t.equal(result.errorCount, 0, basename + ' error free after formatting')
t.equal(result.warningCount, 0, basename + ' warning free after formatting')
if (result.errorCount || result.warningCount !== 0) {
// If there is an issue, print the details
console.log(inspect(result, { depth: depth || null }))
}
t.end()
})
})
}
raw[l] = raw[l].slice(0, -1)
}
raw.push('},')
// raw.push(',')
} else {
raw.push(key + ': ' + result + ',')
}
}
parseRaw(result.subs)
raw[raw.length - 1] = raw[raw.length - 1].slice(0, -1)
// raw.unshift(`const { findParent } = require('./framework')\n`)
// fs.writeFileSync(__dirname + '/jsx.transpiled.real.js', raw.join('\n'))
// will make this super nice
const str = result.init + '\n' + raw.join('\n')
standard.lintText(str, { fix: true }, (err, data) => {
if (err) console.log('ERR!', err)
// console.log(data.results[0])
fs.writeFileSync(__dirname + '/jsx.transpiled.real.js', data.results[0].output) //eslint-disable-line
})
return Promise.all(compare.data.files.map(async file => {
if (!whiteList.includes(file.filename)) {
const content = await context.github.repos.getContent(context.repo({
path: file.filename,
ref: branch
}));
console.log(content);
const text = Buffer.from(content.data.content, 'base64').toString();
Object.assign(linterItems, {cwd: '', fix: true, filename: file.filename});
console.log(linterItems);
standard.lintText(text, linterItems, (err, results) => {
if (err) {
console.log('err: ', err);
}
console.log('res', results);
return Promise.all(results.results.map(result => {
console.log(result);
if (result.output) {
console.log('output', result.output);
// Checks that we have a fixed version and the file isn't part of the whiteList
context.github.repos.updateFile(context.repo({
path: file.filename,
message: `Fix lint errors for ${file.filename}`,
content: Buffer.from(result.output).toString('base64'),
sha: content.data.sha,
branch
}));
result.results.forEach(function (result) {
result.messages.forEach(function (message) {
console.log(
' %s:%d:%d: %s%s',
result.filePath, message.line || 0, message.column || 0, message.message,
Args.value('verbose') ? ' (' + message.ruleId + ')' : ''
)
})
})
process.exitCode = result.errorCount ? 1 : 0
}
}
if (scanFile) {
standard.lintText(fs.readFileSync(scanpath).toString(), opts, output)
} else {
standard.lintFiles(scanpath, opts, output)
}
function processFile (file, enc, cb) {
if (file.isNull()) {
return cb(null, file)
}
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Streams are not supported!'))
}
standard.lintText(String(file.contents), Object.assign({
filename: file.path
}, opts), function (err, data) {
if (err) {
return cb(err)
}
file.standard = data
if (data.results[0] && data.results[0].output) {
file.contents = Buffer.from(data.results[0].output)
data.fixed = true
}
cb(null, file)
})
}
exports.format = source => new Promise((resolve, reject) => {
const pretty = prettier.format(source, {
printWidth: 80,
tabWidth: 2,
parser: 'babylon',
singleQuote: true,
trailingComma: 'none',
bracketSpacing: true
})
standard.lintText(pretty, { fix: true }, (err, result) => {
if (err) {
return reject(err)
}
const output = result.results[0].output
if (typeof output !== 'string') {
return reject(new Error('Expected a string back from standard'))
}
resolve(output)
})
})
return new Promise((resolve, reject) => {
standard.lintText(ignoredBlock, standardOptions, (err, results) => {
if (err) return reject(err)
results.originalLine = block.line
results.originalText = block
return resolve(results)
})
})
})).then((results) => {