3 ms·
When I started seriously working with JavaScript, I decided to try to conform to community standards by using JSLint. I was shocked by how terrible JSLint was.
by dietrichepp 13y ago
When I started seriously working with JavaScript, I decided to try to conform to community standards by using JSLint. I was shocked by how terrible JSLint was. It offered corrections for very straightforward constructs such as:
var count = 0;
for (var i = 0; i < arr.length; i++) {
if (some_func(i)) {
count++;
}
}
I have no idea why JSLint would tell me that I should move the definition of "i" to the top of the function (am I supposed to pretend I'm writing ANSI C for obsolete compilers?) and its insistence that "++" is evil in both uses above is equally ridiculous.
I love static analysis, I like tools that automatically format source code (indent, go fmt, emacs), but JSLint is just annoying.
- v413 13y agoYou can use JSHint to fine-tune your linting rules.
- cpeterso 13y agoJSLint recommends declaring vars at the top of the function because vars have function-scope regardless of where they appear in the function ("variable hoisting").
- happy_dino 13y agoYour issue is not knowing JavaScript. No point to blame a JavaScript linter.
- PommeDeTerre 13y agoThe real issue is that, as a programming language, JavaScript is poorly designed and quite broken. Its implementors and community have been quite unwilling to fix these issues, even after a decade and a half. As a result of this, it is still riddled with oddities in even extremely simple constructs. Even when one understands the reasoning behind why a tool like JSLint suggests what it does, this doesn't change the fact that dietrichepp's observations are correct. JavaScript's scoping and variable hoisting are unnecessarily broken, leading to convoluted coding practices that wouldn't really be necessary if JavaScript itself wasn't so broken.
- ahoge 13y ago>[JavaScript's] implementors and community have been quite unwilling to fix these issues [...] You can't really fix things. It would break the web. You can only add stuff on top. >JavaScript's scoping and variable hoisting are unnecessarily broken [...] It will get a bit better with ES6's `let` keyword. Annoyingly, that keyword was introduced with Firefox 2.0 (October 24, 2006) but you still can't use it. Even Node.js needs a switch.
- jaredmcateer 13y agoThe ++ thing is due to the fact that JavaScript uses + for concatenation and I've run into real life issues with this, in that if someone writes something like var foo = "The id number is: " + ++this.id + "."; a Minifier may make that like var foo="The id number is: "+++this.id+"."; which is a syntax error. Now of course you should be using a minifier that wouldn't be so stupid but it happened in our staging environment because some former employee used a very basic, yet aggressive minifier in the build process from Staging to Live. JSLint gives you an option to turn it off though, plusplus:false. Same with the variable hoisting warning others have explained.