Skip to content

Instantly share code, notes, and snippets.

@louis-young
Created November 21, 2023 08:35
Show Gist options
  • Save louis-young/b086a3e43ab017dda6ace993095d1b4e to your computer and use it in GitHub Desktop.
Save louis-young/b086a3e43ab017dda6ace993095d1b4e to your computer and use it in GitHub Desktop.
ESLint formatter
module.exports = (results) => {
const byRuleId = results.reduce((map, current) => {
for (const { column, line, ruleId } of current.messages) {
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,
}))
.sort((a, b) => b.total - a.total)
.map((rule) => `${rule.ruleId}: ${rule.total}`)
.join("\n");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment