‘onelineperfile’ is a new custom formatter for ESLint that, unsurprisingly, displays one line per file. Linting details are displayed whether the file passed linting or not.
If you use ESLint you probably already know that it comes with six formatters (a.k.a. reporters) that allow you to change the way that messages output by ESLint are reported.
Briefly, the six styles are:
Stylish (the default formatter)
Checkstyle
Compact
JSLint-XML
JUnit
Tap
Each of these are good for what they do but none of them are exactly what I need, which is output with:
- One line for each file processed
- Each line to indicate the status of the linting; success, error or warning
- Each line to indicate the number of errors / warnings, if any
- No error details to be displayed, I can check and fix that in the editor if needed
- A summary line showing the total number of files processed, the number which passed linting and the number with warnings or errors
The reason for these requirements is to allow the output to be used in an audit trail, for example as the result of running a Git pre-receive hook; I should easily be able to check that a particular file was linted and it’s status.
Luckily, ESLint is very extensible so I created a new formatter — onelineperfile — which meets all of my criteria.
Here’s sample output:
The easiest way to add it to your project is using NPM:
npm install --save-dev eslint-onelineperfile
You can then run it directly from the command line:
eslint --format node_modules/eslint-onelineperfile/onelineperfile.js <span class="keyword operator shell">*</span>.js
If you prefer to automate ESLint you can do so using Grunt ESLint:
grunt.initConfig({ eslint: { options: { format: require('eslint-onelineperfile') }, target: ['*.js'] } }); grunt.loadNpmTasks('grunt-eslint'); grunt.registerTask('default', ['eslint']);
More:
Cool!