Thursday, June 11, 2009

Jslint rhino and custom global options

Jslint is a tool developed by Douglas Crockford which analyses javascript and reports problems with syntax and ensures code quality. Here are my instructions that will enable you to use jslint from the command line with rhino. The problem that I ran into was that I didn't want to have to add the /*jslint eqeqeq:true */ to each of the 400+ files in our pr0ject. By using the following technique it means default options can be supplied to jslint on a global basis.

Download these files
Concatenate them together and save as a new file fulljslintrhino.js

Download Rhino

Extract js.jar

Put fulljslintrhino.js and js.jar in the same directory.

Providing that your java installation has been added to the path it should now be possible to execute the following

java -jar js.jar fulljslintrhino.js YourFileToBeTested.js

To customise the options you need to edit the fulljslintrhino.js file and find the section that you pasted in from rhino.js. Edit the section that looks like this: -

if (!JSLINT(input, {bitwise: true, eqeqeq: true, immed: true,
newcap: true, nomen: true, onevar: true, plusplus: true,
regexp: true, rhino: true, undef: true, white: true})) {

1 Comments:

Anonymous Dominic Mitchell said...

You may also find jslint4java of interest. It automates running JSLint from an ant build (or the command line) fairly easily.

code.google.com/p/jslint4java/

12:36 am, August 11, 2009  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home