admin管理员组文章数量:1334133
I am using the lodash library in my express application. Whenever I include lodash like:
var _ = require('lodash')
jshint plains 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 plaining.
How do I ask jshint to ignore this error in my node code ?
I am using the lodash library in my express application. Whenever I include lodash like:
var _ = require('lodash')
jshint plains 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 plaining.
How do I ask jshint to ignore this error in my node code ?
Share Improve this question edited Aug 4, 2015 at 12:19 runtimeZero asked Aug 4, 2015 at 12:15 runtimeZeroruntimeZero 28.1k28 gold badges79 silver badges130 bronze badges 4- in node _ is a reserved word (it's the value from the last instruction evaluated) – Dario Commented Aug 4, 2015 at 12:22
- Juhana's ment helped resolve. Basically added the following to the top of the file /* jshint -W079 */ – runtimeZero Commented Aug 4, 2015 at 12:23
- @Juhana I'll trust you, but if I remember well in REPL was that. Am I wrong (just for don't do mistakes one more time)? – Dario Commented Aug 4, 2015 at 12:30
- 1 @Dario REPLs are allowed to do whatever they like. But just because they assign the last return value to that variable, that doesn’t make it a reserved word. – poke Commented Aug 4, 2015 at 13:54
2 Answers
Reset to default 5You 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
本文标签: javascriptjshint errorRedefinition of 3939Stack Overflow
版权声明:本文标题:javascript - jshint error : Redefinition of '_' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742358772a2459942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论