@voxpelli/eslint-formatter-summary
v4.2.0
Published
ESLint summary formatter aggregating results by rule
Maintainers
Readme
@voxpelli/eslint-formatter-summary
ESLint formatter aggregating results by rule.
Fork of mhipszki/eslint-formatter-summary.
Features
- aggregated errors / warnings / fixable count per rule
- sort by rule name, number of errors or warnings
- output as markdown table or CSV
TL;DR
This formatter simply aggregates the ESLint results by rule and shows the following output:
It can also be configured to sort results by rule, errors or warnings using env vars e.g.
EFS_SORT_BY=rule EFS_SORT_DESC=true eslint -f @voxpelli/eslint-formatter-summary ./src(see details below).
How to install
npm i -D @voxpelli/eslint-formatter-summaryRequirements
| Tool | Version | Field in package.json |
| ---------- | --------------------------------- | ------------------------- |
| Node.js | The LTS releases of Node.js | engines.node |
| TypeScript | Version >=5.9 (optional) | engines.typescript |
| ESLint | Version >=9 (only flat configs) | peerDependencies.eslint |
How to use
When you run ESLint specify @voxpelli/eslint-formatter-summary as the formatter (see ESLint CLI documentation):
eslint -f @voxpelli/eslint-formatter-summary [file|dir|glob]*Intention
It is a matter of minutes to add ESLint to a new project, however it can be quite challenging to introduce it (or just add a stricter rule set) to existing projects, already large codebases.
Possibly hundreds if not thousands of errors will pop up which can seem overwhelming to be fixed when we see the default formatted output, forcing us to back up from making our code base better / more consistent.
This package provides a custom ESLint formatter to help in these situations to make the right decisions by showing the linting results aggregated by rule. It gives an overview of all rules failing showing the total number of errors and warnings summed up by rule.
Having this summary overview can give us the opportunity e.g. to consider suppressing certain rules for now and bringing them back in later when we are ready to fix them.
Output format
With the default ESLint formatter you might get several thousands of lines of failing rules in various files in the output e.g.:
The Summary Formatter simply aggregates the ESLint results by rule and shows the following output instead:
In the above example we can notice that the comma-dangle rule is responsible for about 2/3 of the failures, so we can consider turning it off or just suppressing it to a warning for now as we can do so with the other failing rules.
Sorting output
Default sorting is by
errorsin adescendingorder
Configuration options can be passed to the formatter to alter the output.
Using theEFS_SORT_BY env var the aggregated results can be sorted by either rule, errors or warnings e.g.
EFS_SORT_BY=rule eslint -f @voxpelli/eslint-formatter-summary ./srcsorted string results are shown in ASCENDING order by default and numbers in DESCENDING order, but the order can be reversed using EFS_SORT_REVERSE=true:
EFS_SORT_BY=rule EFS_SORT_REVERSE=true eslint -f @voxpelli/eslint-formatter-summary ./srcMarkdown output
To output the summary as a markdown table, set EFS_OUTPUT=markdown
EFS_OUTPUT=markdown eslint -f @voxpelli/eslint-formatter-summary ./srcExample:
| Errors | Warnings | Fixable | Rule | | ------ | -------- | ------- | --------------- | | 1 | - | 1 | no-const-assigntest.js | | 1 | - | - | no-undeftest.js | | 1 | - | - | no-unused-varstest.js |
The raw example markdown:
| Errors | Warnings | Fixable | Rule |
| ------ | -------- | ------- | --------------- |
| 1 | - | 1 | <details><summary>[no-const-assign](https://eslint.org/docs/rules/no-const-assign)</summary><ul><li>test.js</li></ul></details> |
| 1 | - | - | <details><summary>[no-undef](https://eslint.org/docs/rules/no-undef)</summary><ul><li>test.js</li></ul></details> |
| 1 | - | - | <details><summary>[no-unused-vars](https://eslint.org/docs/rules/no-unused-vars)</summary><ul><li>test.js</li></ul></details> |CSV output
To output the summary as CSV, set EFS_OUTPUT=csv
EFS_OUTPUT=csv eslint -f @voxpelli/eslint-formatter-summary ./srcExample:
errors,warnings,fixable,rule
1,0,1,"no-const-assign"
1,0,0,"no-undef"
1,0,0,"no-unused-vars"GitHub Actions
When running under GitHub Actions, the formatter automatically appends its markdown output to $GITHUB_STEP_SUMMARY, so failing rules surface on the job summary page. This happens regardless of EFS_OUTPUT — stdout still uses whatever format you configured.
- Skipped when the run is clean (no errors and no warnings).
- Opt out with
EFS_GITHUB_STEP_SUMMARY=false(or0) — useful for jobs that should only emit the formatter's stdout. - If the write fails (e.g. read-only path), a warning is logged to stderr but the lint run continues.
Contribute
Please feel free to submit an issue describing your proposal you would like to discuss. PRs are also welcome!
Run unit tests
npm testTest build project
Once the project is built the distribution version can be tested via passing a .js file to npm run try.
For example:
npm run try test.jsCI build
The project is built on GitHub Actions targeting each supported Node.js versions (see the list above).
During the CI build all source files are linted and all unit tests need to pass resulting in a coverage report.
License
MIT
