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.

java org.mozilla.javascript.tools.shell.Main ~/Library/JSLint/jslint.js ./forum/skins/default/media/js/osqa.main.js
...
...
Lint at line 3 character 37: Missing semicolon.
window.location.reload(true)

Lint at line 6 character 32: Missing space after 'function'.
update_post_score: function(id, inc) {

Lint at line 7 character 28: '$' is not defined.
var $score_board = $('#post-' + id + '-score');

Lint at line 8 character 13: Too many var statements.
var current = parseInt($score_board.html())
...
...

Thougths on adding JSLint to the test suite?

asked 24 Sep '10, 11:16

sghael's gravatar image

sghael
106338
accept rate: 0%


Jslint is to strict, and IMO a bit buggy. Those example you showed are the proof :)

Lint at line 3 character 37: Missing semicolon.

This one can cause warnings on some browsers when in a strict validation environment. Is probably the only relevant error.

Lint at line 6 character 32: Missing space after 'function'

Well, if an engine breaks because of that, than is not an engine, is some really buggy interpreter.

Lint at line 7 character 28: '$' is not defined.

This one is very strange. So we use jquery all over the place, and suddenly the jquery object is not defined?

Lint at line 8 character 13: Too many var statements.

Don't know what this means.

But a bit of validation doesn't hurt I guess.

link

answered 24 Sep '10, 11:38

Hernani%20Cerqueira's gravatar image

Hernani Cerq... ♦♦
17.7k86884
accept rate: 53%

edited 24 Sep '10, 11:39

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:

function dostuff() {
    return
    {
        stuff: 'cool stuff'
    };
}

thing = dostuff();
alert (thing.stuff);

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... ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×23

Asked: 24 Sep '10, 11:16

Seen: 2,064 times

Last updated: 04 Oct '10, 06:39

powered by OSQA