在jshint中使用下划线

Joe*_*Joe 24 javascript jshint angularjs

我正在使用下划线库.

我在运行jshint时得到这个:

[L38:C38] W117: '_' is not defined.
      var approvedAndRequstedCount = _.countBy(products, function(obj) {
Run Code Online (Sandbox Code Playgroud)

警告:任务"jshint:all"失败.使用--force继续.

这是我的配置文件:

{
  "node": true,
  "browser": true,
  "esnext": true,
  "bitwise": true,
  "camelcase": false,
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "indent": 2,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "quotmark": "single",
  "regexp": true,
  "undef": true,
  "unused": true,
  "strict": true,
  "trailing": true,
  "smarttabs": true,
  "globals": {
    "angular": false
  }
}
Run Code Online (Sandbox Code Playgroud)

我猜这是全局选项的东西?我试图添加"_":假但没有运气.有任何想法吗?

fun*_*ost 47

我也有这个问题.

我安装了下划线:bower install -save underscore它在代码中运行良好.不幸的是,jshint没有找到这个参考.你必须告诉jshint你的配置文件中的全局变量,如.jshintrc:

{
  …
  "globals": {
    "angular": false,
    "_": false
  }
}
Run Code Online (Sandbox Code Playgroud)

如果您仍然遇到此问题,则需要确保在执行jshint时包含下划线.我建议将-W117设置为true.确定这些错误可能会导致更多错误.