gruntjsjshintgrunt-contrib-jshint

grunt jshint fail only if more than N errors


I am using jshint to validate my scripts with grunt. I configured it and it works correctly. The only problem is that it either pass (when there are no errors) or fails if there is at least 1 error.

I am aware that I can use --force true in my options to suppress the fail

options: {
  force : true
}

But this is not what I want. I want my validation to fail if there are more than N (let's say 10) errors.

After reading documentation, I thought I can achieve it with "maxerr" : 10 in my .jshintrc file. But this does not solve it. The only thing it does is showing additional warning like Too many errors. (58% scanned). when you already exceed your limit.

So is there a way to fail my validation only if I have more than N errors? By this I mean that validation would pass if I have no errors (which I have right now) but also if I have N-1 errors.


Solution

  • No, grunt-contrib-jshint will always fail if there is at least one error. You would have to add the feature yourself, something like this might work (requires maxErr to be set in the task configuration):

    if(!options.maxErr || results.length > options.maxErr) failed = force;
    

    https://github.com/gruntjs/grunt-contrib-jshint/blob/1a4f4864681e940cbc28cebf36e012b88a240575/tasks/jshint.js#L48