jshint: Redefinition bugs
I am not sure if this is my mistake but it seems like a bug to me, jshint v2.9.1
.
I am getting redefinition warnings on:
var setup = require('../setup/home');
And:
var suite = new benchmark.Suite();
Feel free to correct me but this appears to be a regexp/comparison that is a little too simple.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 21 (4 by maintainers)
That kind of behavior would probably surprise many people.
I agree with you on this. I have submitted a patch so that in Node.js environments, JSHint recognizes that
var
statements in seemingly-global code do not resolve to the global bindings–see gh-2877.So while JSHint is definitely misbehaving here, I recommend that you extend your configuration to only enable the
mocha
option for files that are actually executed in an environment wheremocha
has been loaded. This is not simply a workaround to the bug; it’s actually safer overall. When your entire project is configured withmocha: true
, JSHint cannot consistently detect references to undefined variables.For instance, a source file that is not executed with Mocha might contain the expression
test(123)
without a corresponding declaration fortest
, and JSHint would not issue a warning. That will be a risk even when the underlying bug is fixed.This can be done by creating distinct configuration files for different directories within your project. In the case of https://github.com/tmpfs/rlx, that would involve a new file at
test/.jshintrc
. You can limit duplication by using theextends
option.