Last active
March 6, 2020 20:54
-
-
Save john-humi/0a2d52020e5c695a471d6f062e5ba6e5 to your computer and use it in GitHub Desktop.
Execute Prettier pre-commit
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
| #!/bin/sh | |
| # husky... | |
| FILES=$(git diff --cached --name-only --diff-filter=ACMR "*.js" "*.ts" | sed 's| |\\ |g') | |
| [ -z "$FILES" ] && exit 0 | |
| # Prettify all selected filesi | |
| LINES=$(wc -l <<< $FILES | tr -d '[:space:]') | |
| echo "Running prettier on $LINES files" | |
| echo "$FILES" | xargs prettier --write --config ./package.json | |
| # Add back the modified/prettified files to staging | |
| echo "$FILES" | xargs git add | |
| exit 0 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires husky.