Skip to content

Instantly share code, notes, and snippets.

@timelsass
Created March 7, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelsass/a811d1233eece2a6e62b to your computer and use it in GitHub Desktop.
Save timelsass/a811d1233eece2a6e62b to your computer and use it in GitHub Desktop.
JSHint pre-commit hook
#!/bin/sh
#
# Run JSHint validation before commit.
files=$(git diff --cached --name-only --diff-filter=ACMR -- *.js **/*.js)
pass=true
if [ "$files" != "" ]; then
for file in ${files}; do
result=$(jshint ${file})
if [ "$result" != "" ]; then
echo "$result"
echo "\n"
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