Created
July 27, 2021 15:34
-
-
Save monkpit/f087272ead269130ddf91ee78dca4283 to your computer and use it in GitHub Desktop.
Run prettier for PR files
This file contains hidden or 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 `prettier` is in your `devDependencies` already | |
BASE=$(git merge-base master HEAD) # change master to whatever your trunk branch is | |
FILES=$(git diff --name-only $BASE HEAD | xargs) | |
npx prettier --list-different $FILES | |
# Want eslint too? | |
# npx eslint --ignore-path=.prettierignore $FILES |
This file contains hidden or 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
# npx or yarn | |
# change "git diff develop" to "git diff <trunk_branch_name>", or whatever branch you're targeting in the PR | |
yarn prettier -w $(git diff develop --name-only | grep '.js' | xargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found at: https://stackoverflow.com/questions/47610213/how-do-i-run-prettier-only-on-files-that-i-want-to-commit