Skip to content

Instantly share code, notes, and snippets.

@mingliangguo
Forked from mebibou/pre-commit
Created January 24, 2017 15:40
Show Gist options
  • Save mingliangguo/996a7a51a7064e86af71708e3120abec to your computer and use it in GitHub Desktop.
Save mingliangguo/996a7a51a7064e86af71708e3120abec to your computer and use it in GitHub Desktop.
JSHint and JSCS pre-commit hook
#!/bin/sh
# pre-commit git hook.
files=$(git diff --cached --name-only --diff-filter=ACMR -- \*.js **/*.js)
pass=true
if [ "$files" != "" ]; then
for file in ${files}; do
# Run JSHint validation
result=$(jshint ${file})
if [ "$result" != "" ]; then
echo $result
pass=false
fi
# Run JSCS validation
result=$(jscs ${file})
if [ "$result" != "No code style errors found." ]; then
echo $result
pass=false
fi
done
fi
if $pass; then
exit 0
else
echo ""
echo "COMMIT FAILED:"
echo "Some JavaScript files are invalid. Please fix errors and try committing again."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment