尽管在配置中定义了globals属性,但jshint报告变量未定义

时间:2015-09-21 18:29:56

标签: gruntjs jshint

我有一个功能层应用程序,我正在编写一个jshint gulp任务。

这是一项艰巨的任务:

jshint : {
    options : {
        reporter : require("jshint-stylish"),
        force : true
    },
    all : ["Gruntfile.js", "develop/modules/**/*.js", "develop/components/**/*.js"]
},

我的.jshintrc文件:

{
  "curly" : true,
  "eqeqeq": true,
  "forin" : true,
  "globals" : {
      "angular" : false,  <-- is not defined
      "module" : false,
      "console" : false  <-- Is not defined
  },
  "latedef" : true,
  "maxerr" : 150,
  "undef": true,
  "unused": true,
  "strict": true
}

但是在项目上调用任务时的输出是:

C:\Users\jason\Desktop\work\QAngular\angular>grunt jshint
Running "jshint:all" (jshint) task

develop/modules/login/login.js
  line 1    col 1   Use the function form of "use strict".
  line 3    col 1   'angular' is not defined.
  line 12   col 13  'console' is not defined.
  line 20   col 21  'angular' is not defined.
  line 21   col 34  'angular' is not defined.
  line 27   col 29  'console' is not defined.
  line 31   col 29  'console' is not defined.

根据文档,globals中的.jshintrc设置应该处理此问题。不是。有没有我错过的可能性

1 个答案:

答案 0 :(得分:1)

grunt-contrib-jshint默认情况下使用.jshintrc,您必须通过将jshint.options.jshintrc设置为true或文件路径来明确要求它( https://www.npmjs.com/package/grunt-contrib-jshint#jshintrc):

jshint : {
    options : {
        jshintrc: true,
        reporter : require("jshint-stylish"),
        force : true
    },
    all : ["Gruntfile.js", "develop/modules/**/*.js", "develop/components/**/*.js"]
},