Skip to content

Instantly share code, notes, and snippets.

@jameswritescode
Created June 4, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameswritescode/ed3dc2e61cad963cbd889c0ac70f7980 to your computer and use it in GitHub Desktop.
Save jameswritescode/ed3dc2e61cad963cbd889c0ac70f7980 to your computer and use it in GitHub Desktop.
#!/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