Created
April 6, 2014 00:47
-
-
Save pgpbpadilla/9999991 to your computer and use it in GitHub Desktop.
Git pre-commit hook: Run JSLint for NodeJS projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# find node | |
NODE=$(which node) | |
# if it cannot find a node installation | |
if [[ -z $NODE ]]; then | |
#NodeJS is not installed | |
echo "Please install NodeJS first." | |
exit 1 | |
fi | |
# make sure jslint is installed | |
if [[ ! -d ./node_modules/jslint ]]; then | |
#install jslint locally | |
npm install jslint | |
fi | |
# run JSLint before every commit, don't commit until | |
# JSLint is OK | |
for file in $(git diff --name-only --cached | egrep '.js$'); | |
do | |
$NODE ./node_modules/jslint/bin/jslint.js $file | |
# If the result of the previous command is NOT zero | |
if [ $? -ne 0 ]; then | |
echo "*** ERROR *** : JSLint failed for file: $file, please fix code and recommit" | |
exit 1 | |
fi | |
done | |
# Everything is ok | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.git/hooks
pre-commit
$ chmod a+x .git/hooks/pre-commit