Created
October 4, 2018 11:19
-
-
Save ialarmedalien/952a9d110563eae58e4d5d13a7dde1aa to your computer and use it in GitHub Desktop.
TSV formatter for eslint
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
// 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