-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tools: Add and configure PHPStan static analysis #66693
base: trunk
Are you sure you want to change the base?
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @justlevine! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
||
ignoreErrors: | ||
# @TODO: need to discover these symbols. | ||
- '#Function gutenberg_.* not found.#' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. gutenberg_style_engine_get_styles()
. Only thing close I could find was wp_style_engine_get_styles()
in packages/style-engine
.
Is there some aliasing or build step search-replace that happens? Am I missing a path in base.neon
, or do we need to alias/stub these functions ourselves?
bd2e9c6
to
916c228
Compare
What?
This PR adds a PHPStan configuration along with error baselines though Level 7.
PHPStan errors are not remediated in this PR.
Why?
Mirrors efforts in https://core.trac.wordpress.org/ticket/61175
Error baselines can be used as a list of preexisting tech debt that can be remediated independently of this PR. Baselines go up to PHPStan Level 7, as Level 8 baselines currently conflict with previous levels.
Once a decision is made regarding the PHPStan Level to target, the baselines can be merged/adjusted.
Part of #66598
How?
Run PHPStan
Create a local
phpstan.neon
for remediating errorsphpstan.neon.dist
tophpstan.neon
.parameters.level
to the desired level, and filter out the errors by adding them to theparameters.ignoreErrors
list.composer run analyse
.Remediating errors using the error baselines
While
parameters.ignoreErrors
is used to filter out "unsupported" errors, error baselines are used to suppress preexisting tech debt.This allows for the PR to be merged as is to enforce the rules on new code, while allowing contributors to remediate the existing errors at their own pace. This is in the spirit of 'Avoid unnecessary refactoring'.
To remediate a baselined error, remove the error from the
tests/phpstan/baseline/level-{%N}
file and run PHPStan again.Triaging errors and regenerating baselines
If an error is found to be a false positive (or otherwise not worth fixing), it should be added to the
parameters.ignoreErrors
list in thephpstan.neon.dist
file. When this happens, the baseline file suppressing the error will cause PHPStan to fail.To avoid manual remediation, the baseline files can be regenerated by following the following steps:
Identify the baseline level that contains the error. (Search for the error in
tools/phpstan/baseline
).Change the
parameters.level
inphpstan.neon
to the level identified in step 1.Comment out the
includes
for that level and all levels above it.Run the following command:
# Replace {%N} with the level identified in step 1 composer analyse --generate-baseline tools/phpstan/baseline/level-{%N}.php
Testing Instructions
composer analyse
and confirm PHPStan passes.phpstan.neon.dist
tophpstan.neon
, comment out one of the baselineincludes:
, reruncomposer analyse
and confirm PHPStan fails.Todo
( PRs open. )
gutenberg_*()
functions and*_Gutenberg
classesignoreErrors
candidates.