How can I force JSHint running in grunt to always use the --verbose flag

非 Y 不嫁゛ 提交于 2020-01-02 03:16:12

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/26144621/how-can-i-force-jshint-running-in-grunt-to-always-use-the-verbose-flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!