Skip to content

Instantly share code, notes, and snippets.

@timuruski
Last active February 1, 2019 13:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timuruski/5c263c14dad21b39ce3a to your computer and use it in GitHub Desktop.
Save timuruski/5c263c14dad21b39ce3a to your computer and use it in GitHub Desktop.
Pre-Commit Rubocop check
#!/bin/sh
# Simplified from this script, (less robust and more to the point):
# http://gmodarelli.com/2015/02/code-reviews-rubocop-git-pre-commit/
# Installation: copy this code into <REPO>.git/hooks/pre-commit.sh
# Select only staged Ruby files
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep "\.rb$" | tr '\n' ' ')"
# Check for ruby style errors
if [ -n "$FILES" ]; then
exec rubocop --force-exclusion --format=simple ${FILES}
fi
exit 0
@gtramontina
Copy link

Thanks for this one… I just needed something like it and remembered you have done it! 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment