Skip to content

Instantly share code, notes, and snippets.

@thenormalsquid
Created February 14, 2016 22:59
Show Gist options
  • Save thenormalsquid/d101546864920d02060b to your computer and use it in GitHub Desktop.
Save thenormalsquid/d101546864920d02060b to your computer and use it in GitHub Desktop.
grunt jshint pre-commit hook
#!/bin/sh
# This pre-commit hook prevents lint errors from getting committed
# Requires jshint and grunt
jshintout=$(/usr/local/bin/grunt jshint)
exitcode=$?
files=$(git diff --cached --name-only --diff-filter=ACM | grep "\.js$")
if [ "$files" = "" ]; then
exit 0
fi
if [ $exitcode -eq 0 ]; then
echo "Jshint passed"
else
echo "Commit failed, please fix your hint errors"
echo "$jshintout"
exit 1
fi
# Redirect output to stderr.
exec 1>&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment