Skip to content

Instantly share code, notes, and snippets.

@jozsefs
Last active June 10, 2021 12:14
Show Gist options
  • Save jozsefs/9a1431093c2ad580a4f53e61ce36a853 to your computer and use it in GitHub Desktop.
Save jozsefs/9a1431093c2ad580a4f53e61ce36a853 to your computer and use it in GitHub Desktop.
eslint collect errors warnings counted
// copy eslint output here replace ` to ' before copying to avoid js error
str = ``;
str.split(/\n/)
// get rules from the lines containing warning or error
.map(t => {
const match = t.match(/^\s+(\d+\:\d+).+\s+([0-9@_\/\-a-zA-Z]+)$/);
return match && match[2];
})
// remove nulls
.filter(i => i)
// create object with count
.reduce((acc, rule) => ({...acc, [rule]: acc[rule] ? acc[rule] + 1 : 1}), {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment