-
-
Save malko/373e9b7d6e219d1a6bac to your computer and use it in GitHub Desktop.
JSHint and JSCS pre-commit hook
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 | |
# pre-commit git hook. | |
files=$(git diff --cached --name-only --diff-filter=ACMR -- \*.js **/*.js) | |
pass=true | |
errorJscs=0 | |
errorJshint=0 | |
if [ "$files" != "" ]; then | |
for file in ${files}; do | |
# Run JSHint validation | |
result=$(jshint ${file}) | |
if [ "$result" != "" ]; then | |
echo "jshint: \033[31m$result\033[0m" | |
pass=false | |
errorJshint=$((errorJshint + 1)) | |
fi | |
# Run JSCS validation | |
result=$(jscs ${file}) | |
#if [ "$result" != "No code style errors found." ]; then | |
if [ "$result" != "" ]; then | |
echo "jscs: \033[31m'$result'\033[0m" | |
pass=false | |
errorJscs=$((errorJscs + 1)) | |
fi | |
done | |
fi | |
if $pass; then | |
echo "\033[1;32mOk\033[0m" | |
exit 0 | |
else | |
echo "" | |
echo "\033[1;31mCOMMIT FAILED:\033[0m" | |
echo "Some JavaScript files are invalid. Please fix $(($errorJscs + $errorJshint)) error(s) and try committing again." | |
if [ $errorJscs -gt 0 ]; then | |
echo "$errorJscs Jscs errors"; | |
fi | |
if [ $errorJshint -gt 0 ]; then | |
echo "$errorJshint Jshint errors"; | |
fi | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment