Skip to content

Instantly share code, notes, and snippets.

@luchiago
Last active April 28, 2020 00:46
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 luchiago/9332dd5d60efba9edf7fd1faab39ec37 to your computer and use it in GitHub Desktop.
Save luchiago/9332dd5d60efba9edf7fd1faab39ec37 to your computer and use it in GitHub Desktop.
Hook for pre-commit to check rubocop and erb problems
#!/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