Pre-commit hook to run jslint that works for Git as well as Mercurial
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Instructions and a script that runs JSLint as a pre-commit hook, usable for either Git or Mercurial.

As it says on the tin, JSLint will hurt your feelings. Only use this if you like pain. I take no responsibility for any anguish suffered when using JSLint.

See the JSLint info page for configuration options that you can put in your .js files to avoid some of the complaints.


Update Feb 13, 2011: wbecker has a port of this approach that works for Node.

  • Java, probably at least Java 5. You may already have it on your computer -- type "java -version" on the command line to find out.
  • Rhino (just the js.jar file):
  • jslint.js
  • dvcs_jslint.js, the file that is next to this README.

Put js.jar and jslint.js into a directory, for this example, let's use "dvcs_jslint" as the directory name, and assume it is in your home directory (noted as ~ below).

So, inside ~/dvcs_jslint/ (as an example):

  • js.jar
  • jslint.js
  • dvcs_jslint.js

Now time to configure your DVCS to use this information:


In your .git directory for your local repository, create a file called .git/hooks/pre-commit with the following contents:

exec java -jar ~/dvcs_jslint/js.jar ~/dvcs_jslint/dvcs_jslint.js ~/dvcs_jslint/js.jar ~/dvcs_jslint/jslint.js git

Replace ~/dvcs_jslint/ above with the appropriate path that you set up in the Prerequisites section.


In the .hg directory for your local repository, modify .hg/hgrc to have this line in it:

precommit.jslint = java -jar ~/dvcs_jslint/js.jar ~/dvcs_jslint/dvcs_jslint.js ~/dvcs_jslint/js.jar ~/dvcs_jslint/jslint.js hg

Replace ~/dvcs_jslint/ above with the appropriate path that you set up in the Prerequisites section.


  • I have not tried it on Windows
  • The script assumes English output from the DVCS commands and may break if the format of the DVCS commands are different from the stock installs. See the source of dvcs_jslint.js in case you are unsure.