Running JSLint as Mercurial precommit hook

JSLint is a tool that helps you identify potential problems in JavaScript code. Some experienced developers may disagree with the coding style enforced by the tool, but if you are beginning with JavaScript this tool helps you stay out of troubles.

Mercurial hooks

Mercurial offers a powerful mechanism to let you perform automated actions in response to events that occur in a repository …

Usage: jslint4java [options] file.js ...
Options:
--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.)
--encoding Specify the input encoding
--eqeqeq If === should be required
--es5 If es5 syntax should be allowed
--evil If eval should be allowed
# Many more (...)

jslint

jslint is a shell script wrapper for calling jslint4java, e.g.

#!/bin/sh
# Note: Modify the path where the .jar is located
java -jar /home/iperdomo/tools/jslint4java/jslint4java-1.4.4.jar --evil $1

jscheck-hg

jscheck-hg is a simple shell script that checks for modified or added JavaScript files and jslint them

Defining jscheck-hg as precommit hook

With all the components in place, you just need to add the hook to the repository metadata, for this modify the .hg/hgrc file, e.g.

[hooks]
precommit = /path/to/jscheck-hg

Openbravo specifics

Last Friday, the modules for 3.0 were merged into pi, so all the components required for setting this hook are already in the repository. jslint4java, jslint, jscheck-hg are part of the org.openbravo.client.kernel module.

You just need to add the precommit hook to your repository using the jscheck-hg available in org.openbravo.client.kernel/jslint. Open your .hg/hgrc and add the following lines: