Last active
June 2, 2017 18:29
-
-
Save mozfreddyb/5e276f2832aa2e487fad8ce3b01de7dd to your computer and use it in GitHub Desktop.
doesnt fix, but comment-out violations to a specific eslint rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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