Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
doesnt fix, but comment-out violations to a specific eslint rule
#!/usr/bin/env nodejs
var fs = require('fs');
var vobj;
const DISABLE_NEXT_LINE = "// eslint-disable-next-line ";
fs.readFile('build/gecko/inline-violations.json', 'utf8', function (err, data) {
if (err) throw err; // we'll not consider error handling for now
vobj = JSON.parse(data);
for (let r of vobj) {
if (r.messages.length == 0) {
continue
}
let changes = {};
for (let message of r.messages) {
if (message.ruleId.indexOf("no-unsanitized") == 0) {
if (changes[r.filePath]) {
changes[r.filePath].push([message.line, message.ruleId]);
} else {
changes[r.filePath] = [[message.line, message.ruleId]];
}
//addToFile(r.filePath, message.line, rulename);
}
}
addToFile(r.filePath, changes[r.filePath]);
}
});
function addToFile(filename, changes) {
fs.readFile(filename, 'utf-8', function(err, data) {
if (err) throw err;
let linesArr = data.toString().split("\n");
let insertions = 0;
for (let index in changes) {
let change = changes[index];
let line = change[0];
let rulename = change[1];
// go to line before, delete nothing, but add comment
let originalLine = linesArr[line-1];
// find out indentation width
let indentWidth = originalLine.length - originalLine.trimLeft().length+1
let identedComment = Array(indentWidth).join(" ") + DISABLE_NEXT_LINE + rulename;
linesArr.splice(line-1+insertions, 0, identedComment);
insertions++;
}
fs.writeFileSync(filename, linesArr.join('\n'));
});
}
freddy@x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.