Skip to content

Instantly share code, notes, and snippets.

@deleteme
Created December 16, 2016 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deleteme/837e76718d51b41fe53b1ff66b7eb0c5 to your computer and use it in GitHub Desktop.
Save deleteme/837e76718d51b41fe53b1ff66b7eb0c5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Pre-commit Git hook to run JSHint on JavaScript files.
#
# If you absolutely must commit without testing,
# use: git commit --no-verify
passed=1
filenames=($(git diff --cached --name-only HEAD))
which jshint &> /dev/null
if [ $? -ne 0 ];
then
echo "error: jshint not found"
echo "install with: sudo npm install -g jshint"
exit 1
fi
for i in "${filenames[@]}"
do
if [[ $i =~ \.js$ ]];
then
jshint $i
if [ $? -ne 0 ];
then
passed=0
fi
fi
done
if [[ passed -eq 0 ]];
then
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment