Last active
February 27, 2019 14:01
-
-
Save aravindgd/f12a244ce7167ccb913523391f26dcd6 to your computer and use it in GitHub Desktop.
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 | |
HAS_STAGED_RUBY_OR_RAKE_FILES=`git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb\|\.rake$'` | |
if [ -z "$HAS_STAGED_RUBY_OR_RAKE_FILES" ]; then | |
echo -e "No ruby or rake files to lint" | |
else | |
echo -e "[RUBOCOP] --> init" | |
FAILS=`bundle exec rubocop | grep 'no offenses detected' -o | awk '{print $1}'` | |
if [ "$FAILS" == "no" ]; then | |
echo -e "[RUBOCOP] --> 👍 approved." | |
else | |
echo -e "[RUBOCOP] --> ✋ You've $FAILS offenses!!!" | |
exit 1 | |
fi | |
fi | |
HAS_STAGED_JS_FILES=`git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.js\|\.coffee$'` | |
if [ -z "$HAS_STAGED_JS_FILES" ]; then | |
echo -e "No js or coffee files to lint" | |
else | |
echo -e "[YARN LINT] --> init" | |
FAILS=`yarn lint | grep '0 errors and 0 warnings' -o | awk '{print $1}'` | |
if [ "$FAILS" == "0 errors" ]; then | |
echo -e "[YARN LINT] --> 👍 approved." | |
exit 0 | |
else | |
echo -e "[YARN LINT] --> ✋ You've got offenses!!!" | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
h/t to https://gist.github.com/pcofilada/5f1bdb4a764fdd5d9df099a536280bb1