Skip to content

Instantly share code, notes, and snippets.

@aravindgd
Last active February 27, 2019 14:01
Show Gist options
  • Save aravindgd/f12a244ce7167ccb913523391f26dcd6 to your computer and use it in GitHub Desktop.
Save aravindgd/f12a244ce7167ccb913523391f26dcd6 to your computer and use it in GitHub Desktop.
pre-commit
#!/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
@aravindgd
Copy link
Author

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