Skip to content

Instantly share code, notes, and snippets.

@ialarmedalien
Created October 4, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ialarmedalien/952a9d110563eae58e4d5d13a7dde1aa to your computer and use it in GitHub Desktop.
Save ialarmedalien/952a9d110563eae58e4d5d13a7dde1aa to your computer and use it in GitHub Desktop.
TSV formatter for eslint
// output eslint results in TSV format
module.exports = function ( results = [] ) {
const sep = "\t"
, severity = [ '', 'warning', 'error' ]
, path = require( 'path' )
, eslint = require( 'eslint' )
, cwd = process.cwd()
, header = function () {
console.log( [ 'file', 'line', 'column', 'severity', 'fixable', 'code', 'description' ].join( sep ) );
}
, lintfree = function () {
console.log( 'All files lint free!' );
}
, fixable = {}
, linter = new eslint.Linter()
;
let found = false
, rules = linter.getRules()
;
rules.forEach( ( val, key ) => {
if ( val.meta.fixable ) {
fixable[key] = true;
}
});
results.forEach( r => {
if ( r.messages.length > 0 ) {
if ( !found ) {
header();
found = true;
}
const file = path.relative( cwd, r.filePath );
r.messages.forEach( m => {
console.log( [
file
, m.line
, m.column
, severity[ m.severity ]
, m.ruleId && fixable.hasOwnProperty(m.ruleId) ? 'true' : 'false'
, ( m.ruleId
? m.ruleId
: m.message.indexOf('Parsing error') !== -1
? 'parse-error'
: '-' )
, m.message
].join( sep ) );
});
}
});
if ( !found ) {
lintfree();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment