Running JSLint as Mercurial precommit hook
Mercurial offers a powerful mechanism to let you perform automated actions in response to events that occur in a repository …
jslint4java is just a Java wrapper around JSLint and gives you the possibility to run it command line, e.g.:
java -jar jslint4java-1.4.4.jar application.js jslint:application.js:11:9:Line breaking error ')'. jslint:application.js:11:10:Missing semicolon.
Some of the options are for the tool are:
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 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
#!/bin/sh # Note: Modify the path location for jslint (the previous script) hg st -man | awk '/.js$/' | xargs -rn1 path/to/jslint || exit 1
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
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:
[hooks] precommit = ./modules/org.openbravo.client.kernel/jslint/jscheck-hg