Validate files with ESLint
npm install grunt-eslint> Validate files with ESLint

``sh`
npm install --save-dev grunt-eslint
`js
require('load-grunt-tasks')(grunt);
grunt.initConfig({
eslint: {
target: ['file.js']
}
});
grunt.registerTask('default', ['eslint']);
`
`js
const noAlertRule = require('./conf/rules/no-alert');
grunt.initConfig({
eslint: {
options: {
overrideConfigFile: 'conf/eslint.js',
plugins: {
noAlertRule
}
},
target: ['file.js']
}
});
`
`js
const js = require('@eslint/js');
grunt.initConfig({
eslint: {
options: {
extends: [js.configs.recommended]
},
target: ['file.js']
}
});
`
`js`
grunt.initConfig({
eslint: {
options: {
format: './node_modules/eslint-tap/index.js'
},
target: ['file.js']
}
});
`js`
grunt.initConfig({
eslint: {
options: {
outputFile: 'eslint-results.xml',
format: 'checkstyle'
},
target: ['file.js']
}
});
This will output in checkstyle format to both the console and eslint-results.xml. To suppress console output and only write to the file, add silent: true.
`js`
grunt.initConfig({
eslint: {
options: {
flags: ['v10_config_lookup_from_file']
},
target: ['../project1/scripts/*/.js']
}
});
See the ESLint options.
In addition the following options are supported:
Type: array | object
Requires ESLint 9.22+
Shareable configs to extend.
Type: array
Feauture flags to pass to ESLint.
Type: string\'stylish'
Default:
The 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. When specified, the report is written to both the console and the file unless silent is true.
Type: boolean\false
Default:
Report errors only.
Type: boolean\false
Default:
Suppress console output. When used with outputFile, only writes to the file.
Type: number\-1
Default: (Means no limit)
The number of warnings to trigger non-zero exit code.
Type: boolean\true`
Default:
Fail the build if ESLint found any errors.