Monday, August 17, 2009

JSLint with Eclipse

Some simple steps to check your JavaScript Code with JSLint:

  1. download and install JSRhino
  2. make it somehow available, e.g. create a js.bat (one line: java -jar "path/to/rhino/js.jar" %*
  3. download JSLint and put it in some folder, e.g. /path/to/jslint.js
  4. Add an external tool configuration in Eclipse:

    Location: path/to/js.bat

    Working Directory: ${workspace_loc}

    Arguments: path/to/jslint.js ${resource_loc}

  5. you can now check your JavaScript code with JSLint by calling this external tool.

Enjoy.

P.S.: There is a very interessting talk by Douglas Crockford  (creator of JSON and JSLint) at google tech talk that highlights the good and bad aspects of JavaScript. I liked that a lot.

3 comments:

happygiraffe said...

You might also be interested in jslint4java. This allows you to validate your code directly. It also integrates nicely with an ant build script.

http://code.google.com/p/jslint4java/

Woidda said...

Interesting. Especially the ant task. There might be an JsLint Eclipse Plugin . But I have not tried it yet.

happygiraffe said...

I'd like to write an eclipse plugin, but I haven't gotten around to it yet. :)