Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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