Created
December 6, 2017 10:39
-
-
Save fujimura/4dd362ca7b3d30de088dc92c5f710677 to your computer and use it in GitHub Desktop.
pre-commit hook to run prettier
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
#!/bin/sh | |
# Taken from https://prettier.io/docs/en/precommit.html#option-3-bash-script and added (s)css as target | |
jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" "*.css" "*.scss" | tr '\n' ' ') | |
[ -z "$jsfiles" ] && exit 0 | |
# Prettify all staged .js files | |
echo "$jsfiles" | xargs yarn run prettier --write | |
# Add back the modified/prettified files to staging | |
echo "$jsfiles" | xargs git add | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment