Skip to content

Instantly share code, notes, and snippets.

@robsquires
Created April 8, 2016 12:40
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 robsquires/0b0988539b6e3340de788d68d963c70e to your computer and use it in GitHub Desktop.
Save robsquires/0b0988539b6e3340de788d68d963c70e to your computer and use it in GitHub Desktop.
Run jshint on git commit
#!/bin/sh
# You'll need Jshint available, perhaps 'npm install -g jshint'
files=$(git diff --cached --name-only --diff-filter=ACM | grep "\.js$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
echo "\nValidating JavaScript:\n"
for file in ${files}; do
if jshint ${file} ; then
echo "\t\033[32mJSLint Passed: ${file}\033[0m"
else
echo "\t\033[31mJSLint Failed: ${file}\033[0m"
pass=false
fi
done
echo "\nJavaScript validation complete\n"
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass JSHint but do not.\n"
exit 1
else
echo "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment