Javascript Lint Pre-commit Script March 10, 2013

I've created a GIT pre-commit script called "Sgt Donowitz" (named after the character in the movie Inglorious Bastards). The script enforces Javascript code quality and consistency by using JSHint.

The script runs all new or modified Javascript files against JSHint for every commit; if it finds any issues it simply aborts the commit.

You can configure what rules you want to enforce/ignore by using the config file ".jshintrc" (see here for all the available options).

You can also set rules to ignore any file or directory (e.g. 3rd party libraries) by using ".jshintignore" (it works similarly to ".gitignore" files).

Nowadays you can integrate JS Linting into most IDEs. Whilst this is true, there is nothing stoping you from committing code that doesn't pass JS Linting. That's where Sgt Donowitz comes in: it ensures code goodness remains high at all times by blocking bad/rushed code from being commited.

In a nutshell, Sgt Donowitz will force you to keep your JS code quality high and consistent. To setup the pre-commit script, simply run the following command from your project's root:

curl -s jt.io/lint | sh

The source code is published on Github feel free to tweak it, create an issue or leave a comment... In the meantime: "The beatings will continue until morale improves".