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.