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

Viewed 1942

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
4 Answers

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,
)

You might find this userful, it will give you the number of each type of error

https://www.npmjs.com/package/eslint-formatter-summary-chart

% eslint --format summary-chart src
 
==== Files ====
bar.js : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  33.33%
foo.js : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  66.67%
 
 
==== Rules ====
constructor-super     : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  16.67%
no-cond-assign        : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  16.67%
no-constant-condition : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  16.67%
no-debugger           : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  16.67%
no-unused-vars        : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇  33.33%

In a shell script (bash or zsh, for example) you can count the lines of errors output by eslint using wc, and echo it to the console.

ERRCOUNT=$(eval "eslint | wc -l")
echo $OUTPUT errors

Example result:

185 errors
Related