|
I ran osqa.main.js through JSLint (Javascript validator) and see a lot of errors. Some are just based on JSLint being very strict (not a bad thing when it comes to Javascript). Others are problems that can cause JS engines (particularly IE) to behave poorly. IE is particularly bad about things like missing semi-colons at the end of lines, of which there are a few error in the osqa.main.js file.
Thougths on adding JSLint to the test suite? |
|
Jslint is to strict, and IMO a bit buggy. Those example you showed are the proof :)
This one can cause warnings on some browsers when in a strict validation environment. Is probably the only relevant error.
Well, if an engine breaks because of that, than is not an engine, is some really buggy interpreter.
This one is very strange. So we use jquery all over the place, and suddenly the jquery object is not defined?
Don't know what this means. But a bit of validation doesn't hurt I guess. 1
JSLint is configurable to turn off warnings vs errors, if the warnings are an annoyance. IMO, It is worth using, if for no other reason than catching poor syntax (missing semi-colons, and missing brackets). One missing semi could mean a lot of broken JS. One is enough. JSlint does seem to be the most popular validator, but I'm not married to JSLint, so if you know of another validator you'd rather use, then lets go with that. The more important thing is to use something. Btw, there are good explanations for each of these error / warning outputs online, so they all do have some real in the field backing. For example: '$' is not defined -> http://themaingate.net/dev/jquery/is-not-defined-error There is likely a race condition based on order of loading files. It may not be a problem, but if someone starts to move the order of loading on JS files it could manifest.
(24 Sep '10, 12:51)
sghael
Well, I don't know any other syntax checker (nor am I a big fan off those thing :) But i do like good code formatting. The missing semicollon can in fact lead to some errors, when browsers do that thing of semicollon injection or whatever is called, but that is problematic even if you never forget it. Heres a sample of code that will fail because of that:
The problem here is that the language allows both styles at once. As for the explanation you proposed, there is no such things as race conditions in javascript, since it's single threaded. But please, don't take me wrong, I believe that validation and stuff are important. Just saying that we should not believe in everything JSLint (or others) have to say.
(24 Sep '10, 13:29)
Hernani Cerq... ♦♦
The race condition is not in the javascript execution (it's not a runtime race condition). It's a race condition in the loading of files and functions. If the loading of functions can occur differently on different javascript engines, you can end up in a state where a function is called before it is defined. That is why JSLint is warning "'$' is not defined ". We can call it something other than a race condition if that helps, but at the end of the day this isn't a phantom issue. Its real, and can /will manifest on slower JS engines or when a browser downloads or loads JS files slowly. Agree that we don't need to believe everything that JSlint says, but in this case I'm pretty sure JSLint is right.
(03 Oct '10, 23:53)
sghael
True, very old browsers will probably parse the js files in some undefined way. But that's not the case with 99.9% of the browsers used nowadays, even ie6 remainings. All browsers block the execution of javascript while a file is being downloaded. I believe that the biggest discussion nowadays is more about people trying to workaround blockings for some performance reasons, see this for example.
(04 Oct '10, 06:39)
Hernani Cerq... ♦♦
|