Pre-commit hook: Only use local copies of phpcs and phpcbf #44628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes proposed in this Pull Request
In theory, we run the PHPCBF auto-formatter in our pre-commit hook. In practice, this has been failing, and I suspect has been the source of a number of PRs being submitted with PHP lint errors that PHPCBF could auto-fix -- see e.g. #43817.
The reason for this is that our pre-commit hook will preferably use a system-wide installed copy of those tools; however, there's no guarantee that dependencies, such as the WordPress Coding Standards, are also available globally. They will however be installed locally through a simply
compose install
, as will PHPCS and PHPCBF, and our pre-commit hook already has messaging to instruct the user to do so.The fix is thus to never use the globally installed versions of PHPCS and PHPCBF, but always the locally installed ones, and if they can't be found, instruct the user to run
compose install
.Testing instructions
Prerequisites:
phpcs -i
.To reproduce the issue:
vendor/
subfolder from your local Calypso directory (this holds files installed by Composer).Make sure your editor isn't configured to format on save!
Which isn't very helpful 🙁
To reproduce the fix:
composer install
).