【问题标题】:jshint reporting variables undefined despite globals property defined in configuration尽管在配置中定义了全局属性,但 jshint 报告变量未定义
【发布时间】:2015-09-21 18:29:55
【问题描述】:

我有一个功能层应用程序,正在为它编写一个 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.

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

【问题讨论】:

    标签: gruntjs jshint


    【解决方案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"]
    },
    

    【讨论】:

    • 我错过了文档中jshintrc 的默认null 值。感谢您指出。
    猜你喜欢
    • 2023-04-02
    • 2023-02-14
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 2018-07-22
    • 2021-08-18
    相关资源
    最近更新 更多