Created
January 12, 2019 00:15
-
-
Save shannonwells/2dd158ea6caad04c43bc5f5bca617899 to your computer and use it in GitHub Desktop.
Pre commit hook for a rails project that uses yarn
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/sh | |
RUBOCOP_NAMES='\.(rb|rake)$' | |
ESLINT_NAMES='\.(es6|jsx|js)$' | |
PRETTIER_NAMES='\.(es6|jsx|js|scss|json)$' | |
RUBOCOP_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E $RUBOCOP_NAMES) | |
ESLINT_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E $ESLINT_NAMES) | |
PRETTIER_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E $PRETTIER_NAMES) | |
if [[ ! -z $RUBOCOP_FILES ]] | |
then | |
echo "===Running Rubocop===" | |
echo $RUBOCOP_FILES | xargs bundle exec rubocop -a --force-exclusion || exit 1 | |
echo $RUBOCOP_FILES | xargs git add | |
fi | |
if [[ ! -z $ESLINT_FILES ]] | |
then | |
echo "===Running Eslint===" | |
echo $ESLINT_FILES | xargs ./node_modules/.bin/eslint --fix || exit 1 | |
echo $ESLINT_FILES | xargs git add | |
fi | |
if [[ ! -z $PRETTIER_FILES ]] | |
then | |
echo "===Running Prettier===" | |
echo $PRETTIER_FILES | xargs ./node_modules/.bin/prettier --write || exit 1 | |
echo $PRETTIER_FILES | xargs git add | |
fi | |
echo "===Linting passed===" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment