Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active May 30, 2021 03:26
Show Gist options
  • Save max-mapper/72f184b5206fc9e94d4ea0bba92aaa68 to your computer and use it in GitHub Desktop.
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
#!/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