Skip to content

Instantly share code, notes, and snippets.

@mkrishnan-codes
Last active August 5, 2022 11:56
Show Gist options
  • Save mkrishnan-codes/7d494a179092178849e348ce3579f520 to your computer and use it in GitHub Desktop.
Save mkrishnan-codes/7d494a179092178849e348ce3579f520 to your computer and use it in GitHub Desktop.
Get the unique errors reported from ESLint by using custom formatters
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");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment