Skip to content

Instantly share code, notes, and snippets.

@shannonwells
Created January 12, 2019 00:15
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 shannonwells/2dd158ea6caad04c43bc5f5bca617899 to your computer and use it in GitHub Desktop.
Save shannonwells/2dd158ea6caad04c43bc5f5bca617899 to your computer and use it in GitHub Desktop.
Pre commit hook for a rails project that uses yarn
#!/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