Search code examples
terminalconsoleoutputcommand-line-interfaceeslint

How to print out only the number of eslint errors in the terminal?


The project I'm working with has a huge code-base, which means that if I do eslint *.js in the terminal, I get thousands of lines in the output. I want to tweak this command only to print out the number of errors, not to actually list all the errors one by one.

What to do to make my results similar to this:

96 problems

Solution

  • Thinking a bit more, if you really just want a single number, then create your own formatter that would look something like this.

    const errorsInFile => (el, currentEl) => el + currentEl.errorCount
    
    module.exports = function (results) {
      return `${results.reduce(errorsInFile, 0)} problems`
    }
    

    Or just for fun, we could do it functionally with Ramda

    import { map, pipe, prop, reduce, sum } from 'ramda'
    
    const sumArgs = (...args) => sum(args)
    const nProblems = n => `${n} problems`
    
    module.exports = pipe(
      map(prop(‘errorCount’),
      reduce(sumArgs),
      nProblems,
    )