Using jslint4java on the command line

jslint4java can be run as an executable jar file:

$ java -jar jslint4java-${project.version}.jar
usage: jslint [options] file.js ...
  --adsafe   If adsafe should be enforced
  --bitwise  If bitwise operators should not be allowed
  --browser  If the standard browser globals should be predefined
  --cap      If upper case html should be allowed
  --css      If css workarounds should be tolerated
  --debug    If debugger statements should be allowed
  --devel    If logging should be allowed (console, alert, etc.)
  --eqeqeq   If === should be required
  --es5      If es5 syntax should be allowed
  --evil     If eval should be allowed
  --forin    If for in statements must filter
  --fragment If html fragments should be allowed
  --immed    If immediate invocations must be wrapped in parens
  --indent=  The number of spaces used for indentation (default is 4)
  --laxbreak If line breaks should not be checked
  --maxerr=  The maximum number of warnings reported (default is 50)
  --newcap   If constructor names must be capitalized
  --nomen    If names should be checked
  --on       If html event handlers should be allowed
  --onevar   If only one var statement per function should be allowed
  --passfail If the scan should stop on first error
  --plusplus If increment/decrement should not be allowed
  --predef=  The names of predefined global variables.
  --regexp   If the . should not be allowed in regexp literals
  --rhino    If the rhino environment globals should be predefined
  --safe     If use of some browser features should be restricted
  --strict   Require the "use strict"; pragma
  --sub      If all forms of subscript notation are tolerated
  --undef    If variables should be declared before used
  --white    If strict whitespace rules apply
  --widget   If the yahoo widgets globals should be predefined
  --windows  If ms windows-specigic globals should be predefined

  --help     Show this help
  --jslint=  Specify an alternative version of jslint.js

using jslint version 2010-06-27

The list of options is derived from the Option enum. For fuller documentation of each option, see the jslint web site.

You must pass a number of javascript files on the command line. For each one, jslint4java will produce a list of errors on stdout. If any errors are found, an exit code of 1 will be returned.

Sample error output:

$ cat dodgy.js
someVar = 42
$ java -jar jslint4java-${project.version}.jar dodgy.js
jslint:dodgy.js:0:12:Missing semicolon.

The fields are colon separated and consist of:

  1. The fixed string "jslint"
  2. The filename
  3. The line number
  4. The column number
  5. The error

Most command line flags are boolean. If you wish to pass a value to a flag (e.g. --indent), add it using an equals. For example:

$ cat happy.js
var x;
if (x) {
  x = 42;
$ java -jar jslint4java-${project.version}.jar --white happy.js
jslint:happy.js:2:2:Expected 'x' to have an indentation of 4 instead of 2.
$ java -jar jslint4java-${project.version}.jar --white --indent=2 happy.js

To pass a list of predefined global variables, give a comma separated list of names to --predef, e.g.

$ cat globals.js
$ java -jar jslint4java-${project.version}.jar --undef globals.js
jslint:globals.js:1:1:'foo' is not defined.
jslint:globals.js:1:5:'bar' is not defined.
$ java -jar jslint4java-${project.version}.jar --undef --predef=foo,bar globals.js

You can specify an alternative jslint.js in case the version supplied doesn't suit you (for example there is a newer version available). To use another jslint, specify --jslint=/some/where/jslint.js on the command line.