Last active
April 2, 2021 11:38
-
-
Save kidroca/338ef55ae7aeb6b9f983170d34a27253 to your computer and use it in GitHub Desktop.
Custom eslint formatter (reporter) making multiple reports for a single lint run
This file contains hidden or 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
const fs = require('fs'); | |
const fileFormatter = require('eslint/lib/cli-engine/formatters/html'); | |
const outputFormatter = require('eslint/lib/cli-engine/formatters/stylish'); | |
function formatter(results = [], data) { | |
saveA11yReport(results, data); | |
const output = outputFormatter(results, data); | |
return output; | |
} | |
function saveA11yReport(results, data) { | |
// a11y errors and warnings | |
const a11yRelated = results | |
.filter(r => r.messages.some(m => m.ruleId.startsWith('jsx-a11y/'))) | |
.map(r => { | |
const messages = r.messages.filter(m => m.ruleId.startsWith('jsx-a11y/')); | |
return { | |
...r, | |
messages, | |
errorCount: messages.filter(m => m.severity == 2).length, | |
warningCount: messages.filter(m => m.severity == 1).length, | |
}; | |
}); | |
const a11yHtml = fileFormatter(a11yRelated, data); | |
fs.writeFileSync('./dist/a11y.report.html', a11yHtml, 'utf8'); | |
} | |
module.exports = formatter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage:
eslint -f ./custom-lint-formatter "./src/**/*.{js,jsx,ts,tsx}"
or in package.json