Run eslint + prettier on only files that you've staged/commited on the current branch
#!/usr/bin/env bash | |
# chmod +x this and save in your PATH. Assumes `eslint` + `prettier` are in your `devDependencies` | |
BRANCH=$(git branch | grep \* | cut -d ' ' -f2) | |
BASE=$(git merge-base master $BRANCH) # change master to whatever your trunk branch is | |
COMMITED=$(git diff --name-only $BASE $BRANCH) | |
STAGED=$(git diff --staged --name-only) | |
FILES=$(printf "$COMMITED\n$STAGED" | sort | uniq) | |
LINT="npx eslint --ignore-path=.prettierignore $FILES" | |
PRETTIER="npx prettier --list-different $FILES" | |
echo $LINT | |
$LINT | |
echo $PRETTIER | |
$PRETTIER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment