jslint4java

A while ago, I wrote a small wrapper around jslint in Perl: JavaScript-JSLint. However, it’s a real pain to use. There’s a dependency on JavaScript, which in turn needs a compiled version of spidermonkey.

On a recent Java project at $WORK, I wanted to use jslint as part of our unit tests—evil JavaScript be gone! I hacked together a small junit test involving Rhino and a filewalker. It’s worked surprisingly well; our JS code has stayed quite readable.

However, I was bugged by the implementation. So, I’ve rewritten it into a slightly more sensible form. This is now available as jslint4java. The main interface is command line, which is nice as it’s completely self-contained now. But there is also an API which lets you call it from unit tests.

  % java -jar jslint+rhino.jar application.js
  jslint:application.js:11:9:Line breaking error ')'.
  jslint:application.js:11:10:Missing semicolon.

It’s also been the first time I’ve used enum classes in Java 5. They’re really cute. Being able to enumerate all possible values at run time is really handy. Plus, being able to define additional methods is really handy.

Future directions include:

  • More help towards integrating this into a junit test easily.
  • An Eclipse plugin would be nice, so that you can get the jslint warnings pop up in the Problems view.

2 Comments to jslint4java

  1. Hmm, good point. Although I suspect that at this point the amount of spell checkers which would need retraining would be substantial…

  2. This is totally off-topic, but I wish people would just agree to drop the intercaps in language names. At least it’s no longer “SmallTalk” – and thankfully that is now considered a faux-pas almost on the scale of “PERL” or “LISP”. Be awfully nice it were just “Javascript” and “Postscript”.

    Anyway, never mind my rambling.