Skip to content

Instantly share code, notes, and snippets.

@alonisser
Created July 15, 2013 09:34
Show Gist options
  • Save alonisser/5998658 to your computer and use it in GitHub Desktop.
Save alonisser/5998658 to your computer and use it in GitHub Desktop.
A naive implentation of a pre commit jslinting hook
#!/bin/sh
# A naive implentation of a pre commit jslinting hook
# First: checking if jshint is installed
retval=`jshint ; echo $?`
if [[ retval -ne 0 ]]
then
echo "You have to install JSHINT for this to work"
echo "npm install -g jshint"
exit 1
fi
# the actual hook
JS_FILES=`git diff --name-only --cached | grep -E '\.(js)'`
for file in $JS_FILES
do
if [[ -f $file ]]
then
echo "linting: $file"
jshint $file
if [[ $? -ne 0 ]]
then
echo "ERROR: with linting $file"
bad_linting=1
else
echo "OK: $file passes linting"
fi
fi
done
if [[ $bad_linting -eq 1 ]] #if some file went wrong
then
echo "FAIL commiting! linting Errors"
exit 1
else
echo "everything OK - moving to commit"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment