

JSLint, The Javascript Verifier - mshafrir
http://www.jslint.com/

======
jrockway
It does catch one thing that my usual testing doesn't: trailing commas. I am
in the habit of defining maps like this:

    
    
       var foo = {
           foo: "bar",
           bar: "baz",
       };
    

This works in Firefox, but not in IE. Arghhh!

Perhaps I should do it Haskell-style:

    
    
        var foo = { foo: "bar"
                  , bar: "baz"
                  };
    

I find that to be pretty ugly, though, and think it's easier to just omit the
trailing comma. Reluctantly.

~~~
alexk
You can use Steve Yegge’s js2 mode, it detects issues of this type and warns
you.

<http://code.google.com/p/js2-mode/>

~~~
mark_h
Just came here to post that. It really is amazing; incredibly handy for
javascript development. (It even warns about redeclaring variables, all kinds
of issues).

------
DanHulton
Such a big fan of JSLint. Debugging thing is a lot easier if you de-lint your
program first, because it gets rid of whole classes of possible errors.

For anyone using Komodo, there's an excellent JSLint plug-in:
<http://community.activestate.com/xpi/kjslint-jslint-komodo>, though you're
limited to the version of JSLint they bundle in the plug-in. If you want to
manually integrate the latest version into Komodo, I wrote a guide here:
[http://www.danhulton.com/blog/2008/01/16/integrate-js-
lint-i...](http://www.danhulton.com/blog/2008/01/16/integrate-js-lint-into-
komodo-edit/)

Seriously - de-lint your JS.

------
wooby
Javascript Lint is a nice Spidermonkey-based syntax checker you can integrate
into your IDE. I installed it with macports, but it's here:
<http://www.javascriptlint.com/index.htm>

In vim, I do: :set makeprg=jsl\ -process\ % which binds :make to a syntax
check of the current file. It's a cool thing to put in an ftplugin.

------
pmjordan
Is there any particularly good, JavaScript-specific reason why the braceless
version of if statements is discouraged?

    
    
      if (foo)
        bar();
    

Or is this just a matter of taste as it is with C, C++, Java, C#, etc.?

~~~
Sephr
It's just a matter of Douglas Crockford's taste and he doesn't like them so
you have to live with it.

~~~
tlrobinson
Along with increment/decrement operators, fall-through cases in switch
statements, foo['bar'] style property access/assignment, bitwise operators,
and a number of other things.

His book ("JavaScript: The Good Parts") contains a lot of good information,
but roughly half is what I would consider "style" preferences.

~~~
adamc
To be fair, he gives a very clear explanation of how he came to his opinion on
case statements -- he started out favoring them. So it's more "opinion
informed by experience" than just "opinion".

------
bbuffone
#Self Promotion Disclaimer - Eclipse Plugin for jsLint

[http://www.rockstarapps.com/joomla-1.5.8/products/jslint-
ecl...](http://www.rockstarapps.com/joomla-1.5.8/products/jslint-eclipse-
plugin.html)

------
camtarn
Unfortunately, JSLint objects strongly to using 'new foo()' without assigning
the result to anything, which is a pain if you're using Prototype AJAX since
firing off an AJAX request is done by calling 'new Ajax.Request(url,
options)'. The only way to get around this seems to be to put parentheses
around the statement - there's no way to turn most individual checks on or
off, unlike other static analysis tools I've used like PMD and FindBugs.

I still use it - because that trailing-comma-in-hash-definition issue in IE is
really annoying.

------
Sephr
I have yet to find something like JSLint that supports ECMA-357 (SpiderMonkey,
TraceMonkey, ActionMonkey, Rhino, and Tamarin). Does anyone know of one?

