Validate files with ESLint.
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
- ESLint uses Esprima for JavaScript parsing.
- ESLint uses an AST to evaluate patterns in code.
- ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
npm install --save-dev grunt-eslint
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-eslint');
See the grunt docs on how to configure tasks and more advanced usage.
grunt.initConfig({
eslint: { // task
target: ['file.js'] // array of files
}
});
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint']);
grunt.initConfig({
eslint: { // task
options: {
config: 'conf/eslint.json', // custom config
rulesdir: 'conf/rules' // custom rules
},
target: ['file.js'] // array of files
}
});
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint']);
grunt.initConfig({
eslint: { // task
options: {
format: require('eslint-tap')
},
target: ['file.js'] // array of files
}
});
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint']);
Type: String
Default: built-in eslint.json
Path to your ESLint config file (eslint.json
).
Type: String
Default: built-in rules directory
Path to a directory with custom rules. Your custom rules will be used in addition to the built-in ones.
Recommended read: Working with Rules
Type: String
Default: require('eslint-stylish')
Name of a built-in formatter or path to a custom one.
Some formatters you might find useful: eslint-stylish (see screenshot), eslint-json, eslint-tap.
MIT © Sindre Sorhus