Wednesday, 12 November 2008

PHP_CodeSniffer and JSLint

PHP_CodeSniffer has had integration with JavaScript Lint for a while, but I recently found out that the excellent online JavaScript verifier, JSLint, can be run from the command line using Rhino.

I've just committed the JSLint sniff into the Squiz standard under the Debug category. The sniff requires you to have jslint.js on your server and rhino installed on the same machine as PHP_CodeSniffer and you need to tell PHP_CodeSniffer where to find it.

$ phpcs --config-set jslint_path /path/to/jslint.js
$ phpcs --config-set rhino_path /path/to/rhino
$ phpcs --standard=squiz /path/to/file.js
Like JavaScript Lint, not all errors and warnings need fixing, so all messages reported by jslint.js are warnings within PHP_CodeSniffer and can be hidden easily.


Anonymous said...

Executed this line
$ phpcs --config-set jsl_path /path/to/jsl

$ phpcs --standard=squiz file.js

and got
$ sh: 1: /home/user/Downloads/jsl-0.3.0/: Permission denied

Any idea?

Greg Sherwood said...

Did you set it like this: phpcs --config-set jsl_path /home/user/Downloads/jsl-0.3.0/jsl

If so, maybe the jsl script is not executable. Can you run it directly?

If you instead set it like this: phpcs --config-set jsl_path /home/user/Downloads/jsl-0.3.0

Change the path to point directly to the jsl executable instead of the directory.