Skip to content

Instantly share code, notes, and snippets.

@bdurand
Last active January 13, 2020 23:34
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 bdurand/014e3fc7608db7e5fdaf92cdcc72b400 to your computer and use it in GitHub Desktop.
Save bdurand/014e3fc7608db7e5fdaf92cdcc72b400 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Run rubocop with automatic fixes on any new or modified git files
set -o errexit
# set -o xtrace
changed_files=`git diff --cached --name-only --diff-filter=ACM | grep -e '\.rb$' | cat`
if [ "$changed_files" != "" ]; then
ruby_version=`cat .ruby-version | tr -d '[:space:]'`
if RBENV_VERSION=$ruby_version ~/.rbenv/shims/rubocop $changed_files; then
exit 0
else
RBENV_VERSION=$ruby_version ~/.rbenv/shims/rubocop -a $changed_files
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment