Skip to content

Instantly share code, notes, and snippets.

@danwakefield
Created January 6, 2022 14:23
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 danwakefield/abd6d8c106b97f055702ef4fe63497e8 to your computer and use it in GitHub Desktop.
Save danwakefield/abd6d8c106b97f055702ef4fe63497e8 to your computer and use it in GitHub Desktop.
Rubocop pre-commit
#!/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