Reputation: 619
I have JSLint Plugin installed in Sublime Text 2. But i don't agree with some of the rules imposed by the JSLint specially this error on declaring variables inside a loop.
Move 'var' declarations to the top of the function.
for (var i = 0; i < 100; i++) { // Line 12, Pos 10
My question is how can i override or disable this rule in JSLint on Sublime Text 2.
Upvotes: 3
Views: 4005
Reputation: 2024
@chanHXC with the new default options in sublime-jslint the var declaration warnings are skipped.
Upvotes: 0
Reputation: 17453
If you have Darren DeRidder's plugin (there are two JSLint plugins for Sublime Text), you do this:
You can set any of jslint's options under preference -> package settings -> jslint -> advanced built settings. See http://www.jslint.com/lint.html#options for a list of options in JSLint.
Now you're going to have a hard time disabling just var declarations within loops. You can turn the vars
option to true, but then JSLint will let you have as many var declarations as you want, anywhere on the page. That can be a misleading practice, as JavaScript has what some call Function Scope and "hoists" declarations to the top of their scope.
EDIT: Argh, I lied. vars
only allows multiple var declaration statements, but they still have to be at the top of the function. It only allows you to do this:
function fnTest() {
var i;
var j; // Oh boy! Two var statements at the TOP of the same function
for (i = 0; i < 100; i++) {
j++;
}
}
and not
function fnTest() {
var j;
for (var i = 0; i < 100; i++) { // still can't do this.
j++;
}
}
Though I'm surprised Crockford doesn't let you do this, I think you're out of luck, and have to use JSHint instead (there seems to be a Sublime plugin for JSHint here, though I haven't used it).
Upvotes: 3