Last active
April 28, 2020 00:46
-
-
Save luchiago/9332dd5d60efba9edf7fd1faab39ec37 to your computer and use it in GitHub Desktop.
Hook for pre-commit to check rubocop and erb problems
This file contains 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
#!/usr/bin/env bash | |
echo "Running pre-commit hook" | |
fileList_rb=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(rb)$') | |
fileList_erb=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(erb)$') | |
if [ ${#fileList_rb} -lt 1 ] && [ ${#fileList_erb} -lt 1 ]; then | |
echo -e "You have no staged .rb or .erb files to test\n" | |
exit | |
fi | |
if [ ${#fileList_rb} -lt 1 ]; then | |
docker-compose run --rm app bundle exec rubocop ${fileList_rb[*]} "$@" | |
if [ $? -ne 0 ]; then | |
echo -e "\nPlease fix the above rubocop issues before committing.\n" | |
exit 1 | |
fi | |
fi | |
if [ ${#fileList_erb} -lt 1 ]; then | |
docker-compose run --rm app bundle exec erblint ${fileList_erb[*]} "$@" | |
if [ $? -ne 0 ]; then | |
echo -e "\nPlease fix the above erblint issues before committing.\n" | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment