7

I have a particular JSHint/Grunt setup in which I would like to accomplish the following:

  1. Load from a single .jshintrc file to allow my IDE linter to pick up my settings
  2. Be able to override single options from the .jshintrc in other grunt tasks
  3. 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?

MaxPRafferty
  • 4,819
  • 4
  • 32
  • 39
  • 2
    For anyone looking for an answer to this, I have filed it as a bug at https://github.com/gruntjs/grunt-contrib-jshint/issues/178 - details can be found there, and I will update this question if the situation changes. – MaxPRafferty Oct 27 '14 at 15:43
  • any update on this, in particular how to get verbose mode? Checked the link but it was closed. – arcseldon Aug 30 '15 at 22:53
  • The grunt contrib jshint seem to believe that they are not responsible for the parameters that they are sending to grunt and will not address (hence the closed question.). I have since moved to eslint which has all the options that I required: https://www.npmjs.com/package/grunt-eslint – MaxPRafferty Aug 31 '15 at 17:52

1 Answers1

0

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)

Oleksandr Knyga
  • 625
  • 9
  • 9
  • Thanks for the answer Oleksander, but Grunt actually allows the 'verbose' flag to be passed in options. That is the purpose of the options property, to pass command line options via config, which is why my first example works. – MaxPRafferty Mar 03 '16 at 15:06
  • The problem lies with grunt-contrib-jshint, who ignore that the options property is reserved for this purpose and use it to configure the tool in the node environment, but do not ignore properties they themselves are not using. This causes the linter to throw errors on valid command line flags, hence the `Bad option: 'verbose'. (E001)`, in spite of the fact that the verbose flag is correctly appended to the jsHint command when it runs (ironically, the "bad option" error is displaying in verbose mode!) – MaxPRafferty Mar 03 '16 at 15:14