I specifically ask about this condition because any straight-forward lex-compatible parser generator will use this pattern.
I would love this as well as often when debugging I'll just throw in a return statement but then jshint (run automatically) complains
@Zugwalt what I ended up doing was modifying my generator to wrap the user specified code in an if(true)
block.
For example:
switch(foo) {
/* ... */
case bar:
if(true) {
/* insert code here */
}
break;
/* ... */
}
This is equivalent to the code without the braces and jshint doesn't complain :)
I don't know if this is older than this functionality, but I was just looking at the source, and the docs for JSLint, and this could do the trick as well
/*jshint -W027*/
The documentation says that sytax turns off those warnings everywhere, so I'm not sure if function scope works with those. Also I would like to note another use case for this is the use of a preprocessor. It would be nice to be able to lint before and after preprocessing if you take the time to set jshint options. So far I'm going to try the approach I just mentioned.
Update: It is function scoped.
Most helpful comment
@Zugwalt what I ended up doing was modifying my generator to wrap the user specified code in an
if(true)
block.For example:
This is equivalent to the code without the braces and jshint doesn't complain :)