Use the jslint command line version.
Integrate the whole thing in Hudson for continuous checking.
On debian/ubuntu, just do
aptitude install rhino and download the
jslint.js file. You don’t need to type the lengthly commandline on that
jslint page: on ubuntu you can just type
path/to/your.js. Beware: as far as I could see, it did not accept
*.js will in fact only test
the first one.
Jslint is pretty picky, so you need to tame it a bit. Most common things you need to do:
Tell it about your globally available variables that you know are prepared
for you by external libraries. Like
$ if you’re using jquery :-)
// jslint configuration; btw: don't put a space before 'jslint' below. /*jslint browser: true */ /*global $, OpenLayers, window, updateLayer */
Some of the things that jslint enforces:
No extraneous or missing commas, semicolons, etcetera. You’re guaranteed that Internet Explorer does not hickup because you forgot one of those.
Stating your variables beforehand. You’re required to state them all at the
beginning of your file or your functions. No more half-way
var xyz =
123;. It enforces good habits in this sense.
It also forces you to change things that are perfectly ok, but that’s pretty
rare. The most common one is that it dislikes the normal “i++” style of
loop. You have to change that into
for (i = 0; i < something; i += 1)
My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.
Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):