Last active
August 5, 2022 11:56
-
-
Save mkrishnan-codes/7d494a179092178849e348ce3579f520 to your computer and use it in GitHub Desktop.
Get the unique errors reported from ESLint by using custom formatters
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
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