Skip to content

Instantly share code, notes, and snippets.

@cuth
Last active August 29, 2015 14:05
Show Gist options
  • Save cuth/ad40a71af9bc4f176a73 to your computer and use it in GitHub Desktop.
Save cuth/ad40a71af9bc4f176a73 to your computer and use it in GitHub Desktop.
Run JSHint before a git commit.
#!/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
if [ "${file}" != "js/StyleConfig.js" ]; then
result=$(jshint ${file})
if [ "$result" != "" ]; then
echo "$result"
pass=false
fi
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