Possible Duplicate:
What good is JSLint if jQuery fails the validation
http://code.jquery.com/jquery-1.4.4.js
Go to there and paste it in http://www.jslint.com
Isn’t Jquery supposed to be valid….
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s far too much work to comply with it AND be cross-browser compliant. JSLint is useful but its only a generic parser. jQuery has good reasons to throw errors in it.
Sometimes you just need simple dirty hacks to get code working in non-compliant browsers.
let’s look at them one by one :
Here jQuery uses
==onnullto check for bothundefinedandnull. Since jQuery is used as an external library it can’t guarantee whether the input we pass to functions will beundefinedornull. It is safer for it check for both.Doing
num === undefined || num === nullto satisfy JSLint is ridiculous.Here JSLint complains about assignment instead of equals check. The reason JSLint throws this error is because its common to type
=instead of==by mistake. Assigning in this while loop is done on purpose to make the code neater.JSLint complains about an empty for block. This here has been done on purpose because we don’t want to do anything with
keyinstead we want to enumerate over all the keys and only care about the last one.JSLint insists on having variables declaration at the top of functions. This is a bit silly and can be ignored if you want to. It’s a matter of style.
And then the parser crashes. Let me remove some of the code crashing it and see if I can find more complaints.
I actually agree with this one
(ua.indexO("compatile") < 0) &&is better.For closures like:
JSLint prefers to see the function invocation in the brackets as a matter of style. I also agree with this one but it really doesn’t matter at all.
Parser is complaining about the reuse of variable
eIn this case we know thatewill only be used locally in that catch block so it doesn’t matter if we alter it outside the catch block. Here I prefer the readability of re-using the variable nameeOk, you caught me on this one. I’m stumped as to why jQuery doesn’t use
===onwindowHere’s one of those cross-browser compliancy bugs that can be fixed but causes bad
codeJSLint says you should always break after your cases. It’s perfectly valid to drop through after a case. In most cases you forgot to
breakbut here this is intentional.The source here speaks for itself. It’s a weird statement but if accessing it like this throws an error then it can be caught. It’s still valid just JSLint tells you "did you really mean to do this?"
Here JSLint complains about the use of
namewhich can conflict withwindow.namein global scope. It’s a "not quite reserved future keyword but still should be avoided". Were in a closure so it’s safe.JSLint’s internal stack can’t handle it. I’m going to stop now.
I think the point is illustrated.
JSLint has a lot of "Are you sure you want to do this" and we’re telling it yes we want to do this. It might look like a mistake but it’s not.