Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using underscore with jshint

Tags:

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?

like image 696
Joe Avatar asked Mar 04 '14 15:03

Joe


1 Answers

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.

like image 124
funwhilelost Avatar answered Nov 02 '22 16:11

funwhilelost