katratxo on Software Development

tail -f /var/log/brain | grep -i software

Improved JSLint check on Mercurial

with 2 comments

We have been working with the previous version of the Mercurial JSLint precommit hook for several months now, and we pretty happy with the results, it catches the most common JavaScript pitfalls.

However this hook was not smart enough, it checked all the modified JavaScript files even if they were not part for the commit, and this situation annoyed some experienced developers:

I have unfinished JavaScript changes, but I’m committing a Java files!! Why this hook is checking files that are not part of the commit!?? I need to do this Java changes now … I’ll disable this hook.

The Solution

The solution is to run the check on the pretxncommit hook, where you have already the list of files that are part of the commit. You can check the modified JavaScript files and if JSLint complains, the transaction is rolled back.

The Code

The changes are simple. Use hg log to get the list of files from $HG_NODE and pass them through JSLint.

Update: The previous version of the script was not working on every case. The problem is that hg log –template ‘{files}’ outputs all the modified files in a single line. That output saw used as input of awk, that was not filtering properly. I found a workaround, perhaps is not the nicest script, but is working.

# Mercurial pretxncommit hook
for i in $(hg log -r $HG_NODE --template '{files}'); do echo $i | awk '/.js$/ | xargs -rn1 /path/to/jslint || exit 1; done;


As many times, thanks to Juan Pablo and the Mercurial Community for providing the way to check only the files part of the changeset.


Written by katratxo

July 30, 2011 at 8:55 am

Posted in Openbravo

Tagged with , , ,

2 Responses

Subscribe to comments with RSS.

  1. Hi,
    Am new to Openbravo. For demo/evaluation and production use which installation can be used? http://wiki.openbravo.com/wiki/Installation

    Didn’t find a forum where i could ask this hence posting here.


    Joseph George

    August 3, 2011 at 7:08 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: