Created
July 6, 2015 21:51
-
-
Save joshuabremer/a944edc6aa8bd6ddd9ee to your computer and use it in GitHub Desktop.
Javascript pre-commit hook
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 | |
red="\033[1;31m" | |
color_end="\033[0m" | |
pass=true | |
echo "\nValidating JavaScript:\n" | |
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$" | sed '/vendor/d') | |
if [ "$files" = "" ]; then | |
exit 0 | |
fi | |
pass=true | |
for file in ${files}; do | |
$(jshint ${file}) &>/dev/null | |
if (( $? == 0 )); then | |
echo "\t\033[32mJSHint Passed: ${file}\033[0m" | |
else | |
echo "\t\033[31mJSHint Failed: ${file}\033[0m" | |
echo "\t\033[31m$(jshint ${file})\033[0m" | |
pass=false | |
fi | |
$(grep -Fq "debugger" ${file}) | |
if (( $? != 1 )); then | |
echo "\t\033[31mdebugger Check Failed: ${file}\033[0m" | |
pass=false | |
fi | |
done | |
echo "\nJavaScript validation complete\n" | |
if ! $pass; then | |
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again.\n" | |
exit 1 | |
else | |
echo "\033[42mCOMMIT SUCCEEDED\033[0m\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment