Skip to content
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

Introduce identifier error formatter #802

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kingdutch
Copy link
Contributor

@Kingdutch Kingdutch commented Sep 27, 2024

PHPStan allows us to ignore by identifier rather than message (as of 1.11). This is slightly less specific than the message is, but has the benefit of being a lot fewer bytes and a lot easier to deduplicate. This significantly reduces the size of the PHP baseline when used for Drupal Core.

Use the new formatter by passing --error-format=identifier_baseline to the phpstan analyze command. Note that you can unfortunately not pipe to the baseline because this clears out the file before PHPStan is started.

⚠️ The baseline file must be empty since the error formatter would otherwise not get any errors to display (as they are all ignored). You can add a return []; at the top of the baseline to easily do this.

In case no identifier is available the formatter falls back to using the message in the same way PHPStan's BaselinePhpErrorFormatter would do.

There's one important difference vs the BaselinePhpErrorFormatter because $message and $file are not escaped using Helpers::escape as is done in PHPStan. Helpers is a class from the nette/di package that's marked as internal. To add that code back we'd need to add nette/di as a dependency to phpstan-drupal or fork the helper.

PHPStan allows us to ignore by identifier rather than message. This is
slightly less specific than the message is, but has the benefit of being
a lot fewer bytes and a lot easier to group. This significantly reduces
the size of the baseline.
@Kingdutch Kingdutch force-pushed the feature/identifier-error-formatter branch from 9887a9f to 7100df6 Compare September 27, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant