Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created July 27, 2016 19:34
Show Gist options
  • Save gregglind/61bf2c75bf57988d3e5ca8c26ba87c41 to your computer and use it in GitHub Desktop.
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.
#!/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