Last active
May 30, 2021 03:26
-
-
Save max-mapper/72f184b5206fc9e94d4ea0bba92aaa68 to your computer and use it in GitHub Desktop.
Run eslint + prettier on only files that you've staged/commited on the current branch
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
#!/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