Created
January 6, 2022 14:23
-
-
Save danwakefield/abd6d8c106b97f055702ef4fe63497e8 to your computer and use it in GitHub Desktop.
Rubocop pre-commit
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
#!/bin/bash | |
# move to `.git/hooks/pre-commit`; run `chmod +x .git/hooks/pre-commit` | |
set -e | |
files=$(git diff --staged --name-only --diff-filter=ACMRTUXB | grep '\.rb$' | tr '\\\n' ' ') | |
# Check we have files before trying to run the tests. | |
# Prevents getting stuck if we only update non .rb files. | |
if [[ -n $files ]];then | |
git diff --staged --name-only --diff-filter=ACMRTUXB | grep '\.rb$' | tr '\\\n' ' ' | xargs --no-run-if-empty bundle exec rubocop -A --config "$(git rev-parse --show-toplevel)/.rubocop.yml" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment