Skip to content

Instantly share code, notes, and snippets.

@monkpit
Created July 27, 2021 15:34
Show Gist options
  • Save monkpit/f087272ead269130ddf91ee78dca4283 to your computer and use it in GitHub Desktop.
Save monkpit/f087272ead269130ddf91ee78dca4283 to your computer and use it in GitHub Desktop.
Run prettier for PR files
#!/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
# 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