I have JSHint setup with multiple subtasks (src, lib, and test) in Grunt which works great. However, as we're just starting out using this setup there are a lot of errors in our many source files.
$ grunt jshint:src
... lots of errors ...
While working on one file at a time, is it possible to re-lint that single file?
$ grunt jshint:src:one.js
... only errors from one.js ...
Update
One complication is that the watch task also has multiple subtasks to fire off different tasks based on which type of file is edited.
watch: {
src: {
files: [ SRC_DIR + "hgm*.js" ],
tasks: [ "jshint:src", "test" ]
},
lib: {
files: [ "lib/hgm-test-setup.js", "lib/hgm.loader.js" ],
tasks: [ "jshint:lib", "test" ]
},
test: {
files: [ "tests/**/*.js" ],
tasks: [ "jshint:test", "test" ]
}
}
The reason for this is that src
and lib
use one .jshint
while test
uses a different one that specifies all the globals used for testing such as assertions. I can combine src
and lib
, but can I override the JSHint config file for test
?
the grunt-contrib-watch-task, provides an example how to configure your tasks, and use the watch-event for linting only changed files:
grunt.initConfig({
watch: {
scripts: {
files: ['lib/*.js'],
tasks: ['jshint'],
options: {
nospawn: true,
},
},
},
jshint: {
all: ['lib/*.js'],
},
});
// on watch events configure jshint:all to only run on changed file
grunt.event.on('watch', function(action, filepath) {
grunt.config(['jshint', 'all'], filepath);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With