質問

I'm using the underscore library.

I get this when running jshint:

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

Warning: Task "jshint:all" failed. Use --force to continue.

This is my config file:

{
  "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
  }
}

I guess it's something with the globals option? I tried to add "_": false but no luck. Any ideas?

役に立ちましたか?

解決

I had this issue as well.

I installed underscore: bower install -save underscore and it worked fine in the code. Unfortunately jshint was not finding that reference. You must tell jshint about your global variables in configuration file like .jshintrc:

{
  …
  "globals": {
    "angular": false,
    "_": false
  }
}

If you continue to have this issue you need to make sure that underscore is included when jshint is executed. I would not recommend setting -W117 to true. Squelching those errors might lead to more bugs.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top