Skip to content

Support reportUnmatchedIgnoredErrors: warning to report unmatched ignores as warnings instead of errors#5627

Open
phpstan-bot wants to merge 1 commit intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-albx568
Open

Support reportUnmatchedIgnoredErrors: warning to report unmatched ignores as warnings instead of errors#5627
phpstan-bot wants to merge 1 commit intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-albx568

Conversation

@phpstan-bot
Copy link
Copy Markdown
Collaborator

Summary

Adds support for setting reportUnmatchedIgnoredErrors to 'warning' (in addition to true/false). When set to 'warning', unmatched baseline entries and unmatched @phpstan-ignore line comments are reported as warnings instead of errors, allowing the build to stay green while still informing the user about stale ignore patterns.

This enables a workflow where teams can safely regenerate baselines without introducing new errors — unmatched ignores are visible but non-blocking, removing the need to temporarily toggle reportUnmatchedIgnoredErrors: false.

Changes

Config schema

  • conf/parametersSchema.neon: Updated both reportUnmatchedIgnoredErrors and per-error reportUnmatched to accept anyOf(bool(), 'warning')

Core logic

  • src/Analyser/Ignore/IgnoredErrorHelper.php: Changed $reportUnmatchedIgnoredErrors from bool to bool|string. Added mergeReportUnmatched() for proper precedence during deduplication (true > 'warning' > false)
  • src/Analyser/Ignore/IgnoredErrorHelperResult.php: Changed type to bool|string. Updated process() to route unmatched config-level ignores to a $warnings array when reportUnmatched === 'warning'
  • src/Analyser/Ignore/IgnoredErrorHelperProcessedResult.php: Added $warnings constructor parameter and getWarnings() method
  • src/Analyser/AnalyserResultFinalizer.php: Changed type to bool|string. Updated addUnmatchedIgnoredErrors() to route unmatched line-level ignores to warnings
  • src/Analyser/FinalizerResult.php: Added $warnings constructor parameter and getWarnings() method
  • src/Command/AnalyseApplication.php: Merged warnings from FinalizerResult and IgnoredErrorHelperProcessedResult into AnalysisResult
  • src/DependencyInjection/ValidateIgnoredErrorsExtension.php: Updated to validate paths when setting is 'warning' (not just true)

Analogous cases probed

  • reportIgnoresWithoutComments: Different concern (requiring comments on @phpstan-ignore), not extended with 'warning' — it doesn't relate to the baseline workflow described in the issue
  • Per-error reportUnmatched: Extended to also accept 'warning', including proper merge logic during deduplication

Root cause

The reportUnmatchedIgnoredErrors setting only supported true/false. Users who wanted to see unmatched baseline entries without failing the build had to temporarily change this to false before regenerating the baseline — a workflow that doesn't scale to larger teams. The 'warning' value provides a middle ground: unmatched ignores are visible in the output but don't cause a non-zero exit code.

Test

Added 4 regression tests in tests/PHPStan/Analyser/AnalyserTest.php:

  • testReportUnmatchedIgnoredErrorsWarningGlobal: Verifies global 'warning' setting produces warnings (not errors) for unmatched patterns
  • testReportUnmatchedIgnoredErrorsWarningPerError: Verifies per-error reportUnmatched: 'warning' produces warnings
  • testReportUnmatchedIgnoredErrorsWarningPerErrorRaw: Same for rawMessage patterns
  • testReportUnmatchedIgnoredErrorsWarningLine: Verifies 'warning' setting produces warnings for unmatched @phpstan-ignore line comments

Fixes phpstan/phpstan#9695

…gnores as warnings instead of errors

- Accept `'warning'` as a new value for both `reportUnmatchedIgnoredErrors` (global)
  and per-error `reportUnmatched` alongside `true`/`false`
- When set to `'warning'`, unmatched baseline/config ignore patterns and
  unmatched `@phpstan-ignore` line comments are reported as warnings
  (non-failing) instead of errors (failing)
- Update `IgnoredErrorHelperResult::process()` to route unmatched ignores
  to a new warnings array when `reportUnmatched === 'warning'`
- Update `AnalyserResultFinalizer::addUnmatchedIgnoredErrors()` to route
  unmatched line ignores to warnings when set to `'warning'`
- Add `getWarnings()` to `IgnoredErrorHelperProcessedResult` and
  `FinalizerResult` to carry warnings through the pipeline
- Wire warnings from both sources into `AnalysisResult` via
  `AnalyseApplication::analyse()`
- Update `parametersSchema.neon` to accept `anyOf(bool(), 'warning')`
- Update `ValidateIgnoredErrorsExtension` to validate paths when the
  setting is `'warning'` (not just `true`)
- Add merge logic for per-error `reportUnmatched` during deduplication
  with precedence: `true` > `'warning'` > `false`
@staabm
Copy link
Copy Markdown
Contributor

staabm commented May 10, 2026

@phpstan-bot I think we should solve this different. revert all the changes and instead implement a new CLI option which allows to regenerate the baseline in a way that outdated errors are ignored, but no new errors will be recorded in the baseline

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.

2 participants