I have a particular JSHint/Grunt setup in which I would like to accomplish the following:
- Load from a single .jshintrc file to allow my IDE linter to pick up my settings
- Be able to override single options from the .jshintrc in other grunt tasks
- Have JSHint always run in verbose mode so that I can always see the warning numbers, without needing to run all of grunt with --verbose
The following allows me to load from the .jshintrc and always run in verbose, but does not allow option overrides. The docs mention that this should be the case, but don't say anything about the verbose option, which works:
jshint: {
options:{
jshintrc: '.jshintrc',
verbose: true,
},
source: {
options: {
ignores: ['src/**/*.test.js'],
},
files:{
src:['src/**/*.js']
}
},
tests: {
options: {
unused: false
},
files: {
src: ['src/**/*.test.js']
}
}
}
To get around the override limitations, it is fairly easy to just have grunt inject the contents of the .jshintrc file into the config, but for whatever reason this causes the linter to now throw "line 0 col 0 Bad option: 'verbose'. (E001)" errors (this runs correctly if i remove the options.verbose = true; line, but without the verbose flag):
jshint: {
options:(function () {
var options = grunt.file.readJSON('.jshintrc');
options.verbose = true;
return options;
}()),
source: {
options: {
ignores: ['src/**/*.test.js'],
},
files:{
src:['src/**/*.js']
}
},
tests: {
options: (function () {
var options = grunt.file.readJSON('.jshintrc');
options.unused = false;
return options;
}()),
files: {
src: ['src/**/*.test.js']
}
}
}
So, given my three criteria, is there a way to configure grunt to run in this way?
How to run jshint on specific file using grunt-contrib-jshint:
./node_modules/grunt-contrib-jshint/node_modules/jshint/bin/jshint --verbose app/sources/modules/dashboard/views/dashboard-performance/dashboard-performance-ctrl.js
there is no way to define verbose mode for grunt jshint in options. And it will not be solved until grunt updates.
(thanks to MaxPRafferty)
来源:https://stackoverflow.com/questions/26144621/how-can-i-force-jshint-running-in-grunt-to-always-use-the-verbose-flag