Skip to content

Instantly share code, notes, and snippets.

@freeatnet
Last active September 7, 2020 17:24
Show Gist options
  • Save freeatnet/2cba26cb8132a48fd3bcaeb7de3423fb to your computer and use it in GitHub Desktop.
Save freeatnet/2cba26cb8132a48fd3bcaeb7de3423fb to your computer and use it in GitHub Desktop.
Disable eslint (or rather, lower the level of violation to a warning) for existing errors given a JSON output of an eslint run
# Command to generate the ignorables
npx eslint --quiet -o ignorable-lint.json --format json --ext '.js' app/
const fs = require('fs');
const { uniq } = require('lodash');
function prependToFile(filePath, insert) {
const data = fs.readFileSync(filePath)
const fd = fs.openSync(filePath, 'w+')
fs.writeSync(fd, insert, 0, insert.length, 0)
fs.writeSync(fd, data, 0, data.length, insert.length)
fs.close(fd, (err) => {
if (err) throw err;
});
}
function insertIgnoresOnViolations(violations) {
violations.forEach(({ filePath, messages }) => {
const ruleIds = uniq(messages.map(({ ruleId }) => ruleId));
const disableStatement = `/* eslint ${ruleIds.map(ruleId => `${ruleId}: "warn"`).join(', ')} */\n\n`;
const insert = new Buffer(disableStatement);
prependToFile(filePath, insert);
})
}
let input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
input += chunk;
});
process.stdin.on('end', function () {
var parsedData = JSON.parse(input);
insertIgnoresOnViolations(parsedData);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment