This differs from the upstream version of grunt-eslint in that
- It binds to fluid-eslint rather than ESLint, in order to include a fully working fix for issue 4931
- It includes a fix for issue 19, outputting the number of linted files, which the grunt-eslint maintainer has refused a fix for
Validate files with ESLint
$ npm install --save-dev grunt-eslint
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
grunt.initConfig({
eslint: {
target: ['file.js']
}
});
grunt.registerTask('default', ['eslint']);
grunt.initConfig({
eslint: {
options: {
configFile: 'conf/eslint.json',
rulePaths: ['conf/rules']
},
target: ['file.js']
}
});
grunt.initConfig({
eslint: {
options: {
format: require('eslint-tap')
},
target: ['file.js']
}
});
ESLint has [many configuration options available](ESLint options); two common ones that are sometimes gotchas:
This prevents ESLint from raising an error when a global expected to be included from another file (such as fluid
or jqUnit
) is not defined, as in this example error message:
122:9 error 'fluid' is not defined no-undef
Valid globals can be defined in comments at the top of an individual JS file:
/* global fluid, jqUnit */
There are fulsome details on configuring the environment, but a common need is to specify that a file should be linted for a node environment. Again, this can be done in comments at the top of an individual JS file:
/* eslint-env node, mocha */
See the ESLint options.
In addition the following options are supported:
Type: string
Default: 'stylish'
Name of a built-in formatter or path to a custom one.
Some formatters you might find useful: eslint-json, eslint-tap.
Type: string
Default: ''
Output the report to a file.
Type: boolean
Default: false
Report errors only.
Type: number
Default: -1
(means no limit)
Number of warnings to trigger non-zero exit code.
MIT © Sindre Sorhus