Created
June 4, 2018 18:32
-
-
Save jameswritescode/ed3dc2e61cad963cbd889c0ac70f7980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
failure_status=0 | |
git_cmd() { | |
git diff --diff-filter=d --cached --name-only | grep -E $1 | |
} | |
if_fail() { | |
if [ $? -ne 0 ]; then | |
failure_status=1 | |
fi | |
} | |
header() { | |
echo "$(tput bold)$1$(tput sgr0)" | |
} | |
files=$(git_cmd '\.(jsx?|graphql)$') | |
if [[ ! -z $files ]]; then | |
header "Running ESLint..." | |
for file in $files; do | |
git show :$file | node_modules/.bin/eslint --stdin --stdin-filename $file | |
if_fail | |
done | |
fi | |
files=$(git_cmd '\.(r(b|u)|rake)$') | |
if [[ ! -z $files ]]; then | |
header "Running RuboCop..." | |
bundle exec rubocop-git --config .rubocop.yml --cached | |
if_fail | |
if [[ ! -z $PRE_COMMIT_USE_REEK ]]; then | |
header "Running reek..." | |
for file in $files; do | |
reek $file | |
if_fail | |
done | |
fi | |
fi | |
if [[ $failure_status -eq 1 ]]; then | |
echo "Please check your code and try again." | |
echo "If you absolutely cannot deal with all the above issues, use git commit --no-verify ..." | |
fi | |
exit $failure_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment