Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gerardroche/php-cs-fixer-pre-commit-hook
PHP-CS-Fixer pre-commit hook
https://github.com/gerardroche/php-cs-fixer-pre-commit-hook
coding-standards git hooks php php-cs-fixer
Last synced: 10 days ago
JSON representation
PHP-CS-Fixer pre-commit hook
- Host: GitHub
- URL: https://github.com/gerardroche/php-cs-fixer-pre-commit-hook
- Owner: gerardroche
- License: gpl-3.0
- Created: 2021-03-02T15:27:55.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T13:46:34.000Z (2 months ago)
- Last Synced: 2024-10-21T06:58:41.605Z (17 days ago)
- Topics: coding-standards, git, hooks, php, php-cs-fixer
- Language: Shell
- Homepage: https://www.gerardroche.com
- Size: 61.5 KB
- Stars: 12
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP-CS-Fixer Pre-Commit Hook
Run [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) before committing code in a Git pre-commit hook.
The fixer runs quietly without making changes to your files, but will stop and print analysis upon first file that needs to be fixed. Only changed files since the last commit are checked, unless configuration files have changed, in which case the fixer runs a full check.
The hook is invoked by `git commit`, and can be bypassed [using the `--no-verify`](https://git-scm.com/docs/githooks#_pre_commit) option:
```sh
git commit --no-verify
```## Environment variables
- `PHP_CS_FIXER_IGNORE_ENV=1`
- `XDEBUG_MODE=off`## Installation
Run the installer.
```sh
./install
```You'll thank me later ;)
### Manual installation
Create the hooks directory and set the [Git hooks path](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehooksPath).
```sh
mkdir ~/.githooks && git config --global core.hooksPath ~/.githooks
```Download, copy, or symlink the `pre-commit` script to `~/.githooks/pre-commit-php` and ensure the file is executable. The installer symlinks the script into the githooks folder.
```sh
chmod 744 ~/.githooks/pre-commit-php
```Create a pre-commit script that calls the php-cs-fixer pre-commit and any local pre-commit script if it exits.
```sh
#!/bin/shif [ -f ~/.githooks/pre-commit-php ]; then
exec ~/.githooks/pre-commit-php
fiif [ -f .git/hooks/pre-commit ]; then
exec .git/hooks/pre-commit
fi
```## License
Released under the [GPL-3.0-or-later License](LICENSE).