Skip to content

Instantly share code, notes, and snippets.

@phcostabh
Created May 14, 2015 18:08
Show Gist options
  • Save phcostabh/a11ebe9f944b0df10584 to your computer and use it in GitHub Desktop.
Save phcostabh/a11ebe9f944b0df10584 to your computer and use it in GitHub Desktop.
#! /usr/bin/env sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi
# Beautify Files
for file in $files; do js-beautify -r $file > /dev/null && git add $file; done
pass=true
echo "\nValidating JavaScript:\n"
for file in $files; do
result=$(jshint ${file})
if [ -z "$result" ]; then
echo "\t\033[32mJSHint Passed: ${file}\033[0m"
else
echo "\t\033[31mJSHint Failed: ${file}\033[0m"
pass=false
fi
done
echo "\nJavaScript validation complete\n"
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Please fix the JSHint errors and try again.\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