Closed mcandre closed 9 years ago
This one is as designed by Crockford.
The vars option allows you to say "var a; var b;" instead of "var a, b;" but only at the top of a scope.
My mistake.
Is there another configuration I can use to disable Move 'var' declarations to the top of the function.
messages?
I don't believe so– this is one of the core design features of jslint as articulated in Crockford's "good parts" philosophy.
There are several unpalatable alternatives:
Of course if you go es6 you will have to transpile or shim browser environments; since only you know the relative costs all I can do is suggest some options.
I respect that JSLint was designed to check against this rule.
I'm asking for a boolean option to explicitly enable/disable this rule, as we do for other JSLint rules.
The boolean options that node-jslint
supports are precisely the ones that jslint
exposes. To add a new option would require a change to the jslint.js
code, and it is the policy of this project to just deliver that code as-is, copied from the douglascrockford/jslint repository.
This project aims to provide a very small bridge for people who want to use the jslint
linter, which many people feel is unreasonably strict, but some people prefer. The main alternative linter is eslint
, which offers fine-grained control over warnings and errors.
I apologize, by the way, because when I was listing options above, I forgot to mention one more: you could change your code so all the var
statements occur at the top of each function/scope. This is the style that jslint
enforces, because it directly parallels the ES5 requirement about hoisting variable declarations and allowing references before the declaration.
Although I can't speculate about Crockford's motives for making var
in the middle of a scope be a fatal error, I find that my own code is improved when I'm forced to see all the variables that I declare in a scope declared up top -- it motivates me to factor my code into smaller scopes with fewer variables in each. Your mileage may vary, of course.
Thank you for explaining all of this to me. I will go upstream with my suggestions :)
Good luck! You might want to arm yourself beforehand by reading http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742 Javascript: the Good Parts
Great resource, thanks!
From what I gather, ECMAScript is so hosed, that we have to try hard to code around it, using JSLint for ways to do things more safely.
It's not quite so bad. ES3 had some really rough parts, but the addition of strict mode in ES5 made a big difference. And ES6 is almost entirely good. The standards are here:
ES5: http://www.ecma-international.org/ecma-262/5.1/
ES6 (draft, unofficial): https://people.mozilla.org/~jorendorff/es6-draft.html
Out of scope.
I can successfully hide whitespace-related JSLint warnings with
"white": true
. But when I try to"vars": true
, JSLint still showsMove 'var' declarations to the top of the function.
warnings.Configuration
https://github.com/mcandre/dotfiles/blob/master/.jslintrc
I am not using a project-local
./.jslintrc
file.System