grunt-contrib-jshint icon indicating copy to clipboard operation
grunt-contrib-jshint copied to clipboard

Run all targets before failing

Open dharkness opened this issue 11 years ago • 2 comments
trafficstars

Our project have four targets for JSHint as some require different .jshintrc options. When you don't specify a target, all are executed which is perfect. However, the other targets are skipped as soon as one reports errors. Using --force or the force option runs all the targets, but then the task itself passes.

I would like all targets to be processed and have the task pass only if each target passed. My current workaround is very cumbersome and repeats information:

grunt.registerTask("lint", "Check coding standards", function(target) {
    if (target) {
        grunt.task.run("jshint:" + target);
    }
    else {
        var done = this.async(),
            targets = { gruntfile: 0, src: 0, lib: 0, test: 0 };
        grunt.util.async.forEachSeries(Object.keys(targets), function(target, next) {
            grunt.util.spawn({
                grunt: true,
                args: [ "jshint:" + target ],
                opts: { stdio: "inherit" }
            }, function(error, result, code) {
                targets[target] = code;
                next();
            });
        }, function() {
            Object.keys(targets).forEach(function(target) {
                var code = targets[target];
                code && grunt.fail.fatal(target + " lint failed.", code);
            });
            done();
        });
    }
});

Is there an easier way that I'm missing? If not, could we extend the force option to add a value that would continue the task and fail at the end if any target had errors? Ideally, omitting force entirely would work like this, but others may be depending on this fail-fast behavior.

dharkness avatar May 27 '14 21:05 dharkness

I don't think jshint should fail and stop the grunt build at all.

jordanst3wart avatar Feb 05 '16 02:02 jordanst3wart

@dharkness were you able to figure out another way to handle this? I'd like to do the same process - execute all tasks before failing.

atdiff avatar May 11 '16 16:05 atdiff