JSLint and JavaScript: The Good Parts.



Hi,

I'm in the process of learning _javascript_ so I can contribute to gnome shell. I state upfront that my js knowledge is still in its infancy.

One of the more interesting resources I have found is _javascript_ : The Good Parts. The author at the end has a bunch of recommendations and also has a static lint checker for _javascript_: 
http://www.jslint.com/

This checks against ECMAscript and also has errors for bad style, and using features that he recommends steering clear of.

As a way to introducing myself to the code base I had a look at running the js code from gnome shell through jslint.com

I ran the attached perl script to get around errors reported for: let, const, and multiple variable assignment (e.g. [a,b] = callFunc();), which appear to be mozilla specific features.

So far I have just looked at panel.js.

I have found some definite errors (against the style guide at least i.e missing semi-colons).

Would a patch for any of the following be worthwhile?

* missing terminal semi-colons.
e.g. foo() // should be foo();

* if statement's with single statement but no braces.
e.g. 
if (foo)
    blah();
//should be
if (foo) {
    blah();
}

* unused variables.
let x = 3;
// x doesn't appear to be referred to again.

* changing use of == and != to === and !== .
if (foo != null) // should be: if (foo !== null)
Crockford is strong on this, referring to == and != as the evil twins to ===/!== .

* Crockford recommends: 
"If a statement doesn't fit on a line, I will break it after a comma or a binary operator. That gives more protection against copy/paste errors that are masked by semicolon insertion."
//changing this
if (fee && fi
    && foe && fum)
//to
if (fee && fi &&
    foe && fum)

Cheers,

Lex.

PS

Also, Crockford has being doing some very interesting lectures about the web and _javascript_ here:
http://yuiblog.com/crockford/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]