Last active
August 31, 2023 08:58
-
-
Save sovetski/b049bdfa27c00cb285fa4c00ad14fcb4 to your computer and use it in GitHub Desktop.
Run husky after any commit, it will run php cs fixer only on the staged files and let you test before committing the formatted verison
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 sh | |
. "$(dirname -- "$0")/_/husky.sh" | |
git diff --name-only HEAD~1..HEAD | grep '\.php$' | xargs ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=my_config.php_cs.dist | |
# You should create a file named "post-commit" in your ".husky" directory | |
# Change the "my_config.php_cs.dist" by your config file | |
# Or use this one to exlude "vendor" and "tools" directories | |
# git diff --name-only HEAD~1..HEAD | grep '\.php$' | grep -Ev '^vendor/|^tools/' | xargs ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php | |
# DON'T FORGET TO RUN "chmod ug+x .husky/*" to make husky files executable | |
# If you want, you can also directly run this command instead of creating manually the file | |
npx husky add .husky/post-commit "git diff --name-only HEAD~1..HEAD | grep '\.php$' | grep -Ev '^vendor/|^tools/' | xargs ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment