Created
January 18, 2014 10:27
-
-
Save jhamon/8488625 to your computer and use it in GitHub Desktop.
JSHint pre-commit hook. To use, place into .git/hooks/ and make executable with chmod. Modified from this SO answer: http://stackoverflow.com/questions/15703065/github-setup-pre-commit-hook-jshint
This file contains hidden or 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 | |
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$") | |
if [ "$files" = "" ]; then | |
exit 0 | |
fi | |
pass=true | |
for file in ${files}; do | |
result=$(jshint ${file}) | |
if [ $? == 0 ]; then | |
echo "\033[32mJSHint Passed: ${file}\033[0m" | |
else | |
echo "\033[31mJSHint Failed: ${file}\033[0m" | |
echo "\033[31m$(jshint ${file} | sed '$d' | sed '$d')\033[0m\n" | |
pass=false | |
fi | |
done | |
if ! $pass; then | |
echo "\033[41mCOMMIT FAILED:\033[0m Please fix the JSHint errors and try again.\n" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment