Created
July 27, 2016 19:34
-
-
Save gregglind/61bf2c75bf57988d3e5ca8c26ba87c41 to your computer and use it in GitHub Desktop.
Takes output from `addon-lint`, and errors or not based on a user-specified set of ignore rules.
This file contains hidden or 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 node | |
/* | |
usage: | |
``` | |
jpm xpi # makes myaddon.xpi | |
npm install addon-linter | |
./node_modules/.bin/addon-linter myaddon.xpi | node addon-lint-consumer.js | |
``` | |
Author: Gregg Lind | |
license: PUBLIC DOMAIN. | |
//example .addonlinterrc | |
ignorerules: | |
LOW_LEVEL_MODULE: true | |
KNOWN_LIBRARY: true | |
*/ | |
var yamljs = require("yamljs"); | |
function loadRules (fn) { | |
var ignored = {}; | |
try { | |
ignored = (yamljs.load(fn)).ignorerules; | |
} catch (err) { | |
} | |
return ignored; | |
} | |
function filterLint(lint, ignored) { | |
['errors', 'notices', 'warnings'].map(function (k) { | |
var filtered = lint[k].filter(function(seen) { | |
return !(seen.code in ignored) | |
}) | |
lint[k] = filtered; | |
}) | |
return lint; | |
} | |
function output(filteredLint) { | |
var show = 0; | |
['errors', 'notices', 'warnings'].map(function (k) { | |
if (filteredLint[k].length) { show = 1}; | |
}) | |
if (show) { console.error(filteredLint); } | |
process.exit(show); | |
} | |
function doTheWork(content) { | |
// your code here | |
var ignored = loadRules(".addonlinterrc"); | |
output(filterLint(JSON.parse(content),ignored)); | |
} | |
// read in all the stdin | |
var content = ''; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function(buf) { content += buf.toString(); }); | |
process.stdin.on('end', function() { | |
// your code here | |
doTheWork(content); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment