Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
Created May 29, 2020 00:10
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 BronsonQuick/cf607d0714737d3919c73642fc9fac14 to your computer and use it in GitHub Desktop.
Save BronsonQuick/cf607d0714737d3919c73642fc9fac14 to your computer and use it in GitHub Desktop.
A gist that feeds diffs into a variable for precommit checks.
# Determine modified and staged files.
JSSTAGED=$(git --no-pager diff --relative --name-only --cached --diff-filter=d -- '**/*.js' \
| xargs -L 1 printf "%s/%s\n" "$PWD")
PHPSTAGED=$(git --no-pager diff --relative --name-only --cached --diff-filter=d -- '**/*.php' \
| xargs -L 1 printf "%s/%s\n" "$PWD")
CSSSTAGED=$(git --no-pager diff --relative --name-only --cached --diff-filter=d -- '**/*.css' \
| xargs -L 1 printf "%s/%s\n" "$PWD")
SCSSSTAGED=$(git --no-pager diff --relative --name-only --cached --diff-filter=d -- '**/*.scss' \
| xargs -L 1 printf "%s/%s\n" "$PWD")
TSSTAGED=$(git --no-pager diff --relative --name-only --cached --diff-filter=d -- '**/*.ts' '**/*.tsx' \
| xargs -L 1 printf "%s/%s\n" "$PWD")
Then feed the vars into the sniffers:
if [ ! -z "$JSSTAGED" ]; then
yarn --cwd $(git rev-parse --show-toplevel)/src eslint $JSSTAGED
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment