Skip to content

Instantly share code, notes, and snippets.

@allan-simon
Last active August 29, 2015 14:08
Show Gist options
  • Save allan-simon/aeebc350a98035ac0257 to your computer and use it in GitHub Desktop.
Save allan-simon/aeebc350a98035ac0257 to your computer and use it in GitHub Desktop.
jshint pre-commit check
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
echo "\nValidating JavaScript:\n"
for file in ${files}; do
result=$(jshint ${file})
if [ "$result" != "" ]; then
echo "\t\033[31mJSHint Failed: ${file}\033[0m"
pass=false
else
echo "\t\033[32mJSHint Passed: ${file}\033[0m"
fi
done
echo "\nJavaScript validation complete\n"
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSHint but do not. Please fix the JSHint 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