Skip to content

Instantly share code, notes, and snippets.

@ialarmedalien
Created October 4, 2018 11:19
Show Gist options
  • Select an option

  • Save ialarmedalien/952a9d110563eae58e4d5d13a7dde1aa to your computer and use it in GitHub Desktop.

Select an option

Save ialarmedalien/952a9d110563eae58e4d5d13a7dde1aa to your computer and use it in GitHub Desktop.

Revisions

  1. ialarmedalien created this gist Oct 4, 2018.
    56 changes: 56 additions & 0 deletions tsv-formatter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    // 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();
    }
    };