PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 15, 2022

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

 August 15, 2022     command-line-interface, console, eslint, output, terminal     No comments   

Issue

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


Answered By - David Bradshaw
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing