I am using the lodash library in my express application. Whenever I include lodash like:
var _ = require('lodash')
jshint complains with the error:
Redefinition of '_'
If I remove the require statement, the application fails and reports that it does not recoginice '_'.
My jshint.rc has the following statement:
"globals": {
"angular": false,
"_" : false
}
But this is so that I can include it in the front-end code without jshint complaining.
How do I ask jshint to ignore this error in my node code ?
You have explicitly told jshint that the global variable _
is read-only.
From the docs:
globals
A directive for telling JSHint about global variables that are defined elsewhere. If value is false (default), JSHint will consider that variable as read-only. Use it together with the undef option.
/* globals MY_LIB: false */
Since you are using require
to explicitly define it, I think you can
remove _
from the globals
list for JSHint to allow assignment to the variable.
If, however, you are using _
without explicitly requiring it and expect it to be present in the environment, then you can set "_" : true
in your .jshintrc
to still allow assignment to it.
In your jshint.rc you can put: "no-native-reassign" : 0
, this will disable the native reassign rule, or you can put /*jshint -W079 */ right before the function where you assign _.
When you don't use _ as a global variable you also should remove it from your Globals in jshint. Or set it to true so jshint doesn't see it as readonly.
sources: JSLint Error explanation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With