Skip to content

Instantly share code, notes, and snippets.

@alexdong
Last active August 29, 2015 14:01
Show Gist options
  • Save alexdong/c56fd74021ee5dd9b53e to your computer and use it in GitHub Desktop.
Save alexdong/c56fd74021ee5dd9b53e to your computer and use it in GitHub Desktop.
jshint pre-commit hook
#!/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 [ "$result" != "" ]; then
echo $result
pass=false
fi
done
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSHint but do not. Please fix the 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