Last active
July 31, 2023 17:59
-
-
Save branneman/5ea56969966332ab528ab5ab2d1a5b4e to your computer and use it in GitHub Desktop.
Group-By-Count ESLint errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :: (String, String) => String | |
const spawn = require('child_process').spawnSync; | |
// :: String => [String] | |
const getRules = raw => raw | |
.split('\n') | |
.map(line => line.trim()) | |
.filter(line => !!line) | |
.filter(line => line[0] !== '/' && line[0] !== '✖') | |
.map(line => line.match(/[a-z-]+$/)[0]); | |
// :: [String] => Object | |
const groupByCount = list => { | |
const dict = {}; | |
list.forEach(item => { | |
dict[item] = dict[item] || 0; | |
dict[item]++; | |
}); | |
return dict; | |
}; | |
// :: Object => [Object] | |
const sortByValue = dict => { | |
const arr = []; | |
for (const key in dict) { | |
if (!dict.hasOwnProperty(key)) continue; | |
arr.push([key, dict[key]]); | |
} | |
arr.sort((a, b) => a[1] < b[1] ? 1 : a[1] > b[1] ? -1 : 0); | |
return arr; | |
}; | |
// :: String => [String] | |
const app = str => sortByValue(groupByCount(getRules(str))); | |
const output = spawn('eslint', ['.'], {encoding: 'utf8'}).stdout; | |
console.log(app(output)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eslint . | grep -v "^[\/✖]" | grep -v '^$' | perl -ne 's/(?:.+) ([\w-]+$)/$1/g; print;' | sort | uniq -c | sort |
it is because of the /
in type of error.
Updated script:
eslint . | grep -v "^[\/✖]" | grep -v '^$' | perl -ne 's/(?:.+) ([\/\w-]+$)/$1/g; print;' | sort | uniq -c | sort
If your package name has @
in it, use this instead:
% cat linter-output.txt | grep -v "^[\/✖]" | grep -v '^$' | perl -ne 's/(?:.+) ([@\/\w-]+$)/$1/g; print;' | sort | uniq -c | sort
Very useful script, thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
count-lint-errors.sh
does not identify the following lines as identical warnings (perhaps because of the quotes):P.S. Very nice command though!!