Skip to content

Instantly share code, notes, and snippets.

@pvcarrera
Created December 26, 2016 19:30
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 pvcarrera/c0d830ac5379741b0f62def2c2dddf47 to your computer and use it in GitHub Desktop.
Save pvcarrera/c0d830ac5379741b0f62def2c2dddf47 to your computer and use it in GitHub Desktop.
#!/bin/sh
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
# Get only the staged files
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep "\.rb$" | tr '\n' ' ')"
echo "${green}[Ruby Style][Info]: Checking Ruby Style${NC}"
if [ -n "$FILES" ]
then
echo "${green}[Ruby Style][Info]: ${FILES}${NC}"
# Run rubocop on the staged files
FAILS=`bundle exec rubocop ${FILES}| grep 'no offenses detected' -o | awk '{print $1}'`
if [ "$FAILS" != "no" ]; then
echo "${red}[Ruby Style][Error]: Fix the issues and commit again${NC}"
exit 1
fi
else
echo "${green}[Ruby Style][Info]: No files to check${NC}"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment