Skip to content

Instantly share code, notes, and snippets.

@timmyc
Created December 18, 2014 17:44
Show Gist options
  • Save timmyc/e4ed93c9e8087c42b406 to your computer and use it in GitHub Desktop.
Save timmyc/e4ed93c9e8087c42b406 to your computer and use it in GitHub Desktop.
jsxhint pre-commit hook
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx*$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
echo "\nValidating .jsx and .js:\n"
for file in ${files}; do
result=$(jsxhint ${file})
if [ "$result" != "" ]; then
echo "\033[31mjsxhint Failed: ${file}\033[0m"
echo "$result"
echo "\n -----\n"
pass=false
else
echo "\033[32mjsxhint Passed: ${file}\033[0m"
fi
done
echo "\njsxhint validation complete\n"
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass jsxhint but do not. Please fix the jsxhint 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