This seems like a basic question but I can't figure out how to do it. This is how to do it in gulp.
I want when I save a file with a jshint error to fail the Grunt build. The output states that jshint failed but Grunt still completes successfully.
grunt.initConfig({
watch: {
js: {
files: ['/scripts/{,**}/*.js'],
tasks: ['newer:jshint:all']
}
}
})
I know there is grunt.fail but how would I use it here?
The following gist will report a
jshinterror via the CLI and fail to execute any subsequent build steps when saving the.jsfile.You will need to adapt according to your requirements :
Directory structure:
package.json
Gruntfile.js
test.js
Testing the demo gist
cdto theprojectdirectory$ npm install$ grunt watchtest.js, (e.g. add a new line to the end of the file), and save the change.The CLI reports the error as follows:
NOTE:
Any subsequent build tasks specified in the
tasksarray of thewatch.jsobject, (e.g.concatas per commented in theGruntfile.js), will not be invoked using this gist as thejshinttask fails (... and theconcattask has not been defined of course!).However, when the JavaScript file/s successfully pass the
jshinttask, any subsequent build tasks that are defined in thetasksarray of thewatch.jsobject will be invoked.I hope this helps!