When it comes to formatting with Eslint, you have the option to utilize custom formatters. One way to approach this is by creating a file named lint-formatter.js
.
module.exports = results => {
const byRuleId = results.reduce(
(map, current) => {
current.messages.forEach(({ ruleId, line, column }) => {
if (!map[ruleId]) {
map[ruleId] = [];
}
const occurrence = `${current.filePath}:${line}:${column}`;
map[ruleId].push(occurrence);
});
return map;
}, {}
);
return Object.entries(byRuleId)
.map(([ruleId, occurrences]) => `${ruleId} (total: ${occurrences.length})\n${occurrences.join('\n')}`)
.join('\n########################\n');
};
In this particular example, errors and warnings are grouped by their respective rule id, but feel free to customize as needed.
To use your custom formatter when running the linter, execute the following command:
eslint -f ./lint-formatter.js
For reference, here's a sample output:
object-curly-spacing (total: 2)
foo/bar.js:2:8
foo/bar.js:3:13
########################
no-trailing-spaces (total: 1)
foo/bar.js:7:11
########################
object-curly-newline (total: 2)
foo/bar.js:14:8
foo/bar.js:15:31
########################
space-infix-ops (total: 1)
foo/bar.js:18:29