JSLint through command line

My workplace insists on using a code quality tool for JavaScript named JSLint.

It's written in JavaScript. So I had to figure out a way to integrate it with my text editor.
To do that, I would first need a command line tool that can execute JS. Once I get that working, I would then send my JS source code over to JSLint.

The JS engine I decided to use is Mozilla's SpiderMonkey.
I downloaded the source code for SpiderMonkey, and then modified it as mentioned here.
I then followed the documentation for building the binaries from source (Link).
Finally I wrote a small script (with JS) that can read my JS source code and send it over to JSLint.

All the required scripts (and binaries for windows) are here: Download.
For windows you will also have to install Microsoft Visual C++ Redistributable package.

To run JSLint over your source code, do a
On Windows
run.cmd full/path/to/your/js/code.js

On Ubuntu
Edit the first line of run.sh ('cd /full/path/to/jslint/direrctory/').
After which, you need to get the spidermonkey shell. You've got two alternatives to do that:
1. Download and install Wine emulator to use js.exe (You will have to edit run.sh to use js.exe).
2. Two options again:

i) Download the source code from Mozilla.
Modify js/src/shell/js.cpp as mentioned at this link.
ii) Download source from here.

Then head over to the build documentation and follow the 'Easy Build' section.
Copy js/src/shell/js file to the JSLint folder.

Finally, to run JSLint over your source code:
./run.sh full/path/to/your/js/code.js

I added the command to Geany (text editor), as follows:
/full/path/to/run.sh %d/%f

If you ever need to update JSLint, get the latest source from github and overwrite jslint.js.
Updated on Feb 7, 2012
blog comments powered by Disqus