JS lint returns a lot of errors, but code still works - good, bad?
-
7Terrible. You should be ashamed. – Brian Roach Apr 24 '12 at 23:19
-
Great answers below, but as an alternative code quality tool that seems to give less errors (and is community driven), take a look at: http://www.jshint.com/ – jlaceda Apr 24 '12 at 23:43
-
1jshint is for sissies who can't handle the fiery furnace of jslint. – david Apr 24 '12 at 23:45
2 Answers
JSLint tells you information about the human-readability of the code. Considering what minified code looks like, I can tell you with confidence that the JavaScript parsing engine doesn't give two hoots what the code looks like, as long as it is syntactically correct.
EDIT: I wouldn't worry anyway. I just pasted my new project's main JS file into it (52Kb, written using a coding style that I can read perfectly) and I got "Error: Too many errors" - and when I increased the maximum error count, it just said "Error: Stopping". My code is apparently so unreadabe that JSLint gives up all hope of processing it after just 9% of the file! But if you were to look at it you'd probably be able to understand it just fine.

- 320,036
- 81
- 464
- 592
-
And sometimes it doesn't even need to by syntactically correct thanks to automatic semicolon insertion. – david Apr 24 '12 at 23:43
-
@david - "Missing" semicolons are not (necessarily) syntax errors. They're _optional_ for most - but not all - JS statements. – nnnnnn Apr 24 '12 at 23:45
-
@nnnnnn If it's syntactically correct without them then why does the parser need to insert them? – david Apr 24 '12 at 23:46
-
@david they can cause problems if omitted! http://bonsaiden.github.com/JavaScript-Garden/#core.semicolon – ajax333221 Apr 24 '12 at 23:50
-
@david - The language specification explicitly makes them optional, so by definition it is not a syntax error to leave them out. (Again, this applies for _most_ cases, but sometimes you do need to include them explicitly.) Contrary to what the page that ajax333221 linked to says, the parser does _not_ guess, it follows a well-defined set of rules. – nnnnnn Apr 24 '12 at 23:51
-
@nnnnnn The language specification makes them 'optional' because so many bad coders were doing it wrong. They are still needed for the program to be correct, the parser just inserts them for you if you don't know how to do it yourself. – david Apr 24 '12 at 23:52
-
@david - I believe you are mistaken sir. The optional semicolon feature was not added to cater to "bad coders" - if they had not been optional from the start then the programs produced by these so-called "bad coders" would never have worked. Nor is a person who understands the language spec and codes accordingly a "bad" coder - the opposite is true: to be a "good" JS coder you must understand the semicolon rules just the same as you must understand how to use if or while or any other core language feature. – nnnnnn Apr 25 '12 at 00:03
-
@nnnnnn Yeah, just like how webpages with malformed html would never have worked? Anyone who understands the semicolon rules will know that it's far better to insert them yourself instead of making the parser do extra work. – david Apr 25 '12 at 00:18
JSLint is a code quality tool as described on http://www.jslint.com/lint.html.
If your js code passes the jslint test it's bound to be:
- Human readable
- Less error prone
- Free of syntax errors
- Free of javascript's bad parts
Cut out of description on jslint.com:
If it finds a problem, it returns a message describing the problem and an approximate location within the source. The problem is not necessarily a syntax error, although it often is. JSLint looks at some style conventions as well as structural problems. It does not prove that your program is correct. It just provides another set of eyes to help spot problems.

- 11,385
- 7
- 52
- 75