Skip to content

Instantly share code, notes, and snippets.

@chrismarksus
Created April 17, 2015 16:01
Show Gist options
  • Save chrismarksus/4b13d8b4d28439705821 to your computer and use it in GitHub Desktop.
Save chrismarksus/4b13d8b4d28439705821 to your computer and use it in GitHub Desktop.
git hooks
#!/bin/sh
#
# Run ctags after a commit
echo ""
echo "Ctags running ==============================="
echo ""
ctags -R .
if (( $? == 0 )); then
echo "Ctags was successful"
else
echo "Ctags failed"
fi
echo ""
echo "Ctags complete =============================="
echo ""
#!/bin/sh
# run jslint on js files
files=$(git diff --cached --name-only --diff-filter=ACM | grep "/js/")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
echo ""
echo "Validating JavaScript:"
echo ""
for file in ${files}; do
result=$(java -jar /PATH/TO/jslint4java-2.0.2.jar --anon --browser --cap --css --fragment --maxerr 999999 --maxlen 10000 --nomen --on --plusplus --predef dojo,dijit,dojox,$ --regexp --sloppy --sub --unde f --vars --white ${file})
if [ "$result" == "" ]; then
echo " Passed: ${file}"
else
echo " Failed: ${result}"
pass=false
fi
done
echo ""
if ! $pass; then
echo "JSLINT: Failed: Your commit contains files that should pass JSLint but do not. Please fix the JSLint errors and try again."
exit 1
else
echo "JSLINT: Success:"
fi
echo ""
echo "JavaScript validation complete"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment