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
Open
Conversation
…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`
Contributor
|
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds support for setting
reportUnmatchedIgnoredErrorsto'warning'(in addition totrue/false). When set to'warning', unmatched baseline entries and unmatched@phpstan-ignoreline 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 bothreportUnmatchedIgnoredErrorsand per-errorreportUnmatchedto acceptanyOf(bool(), 'warning')Core logic
src/Analyser/Ignore/IgnoredErrorHelper.php: Changed$reportUnmatchedIgnoredErrorsfrombooltobool|string. AddedmergeReportUnmatched()for proper precedence during deduplication (true>'warning'>false)src/Analyser/Ignore/IgnoredErrorHelperResult.php: Changed type tobool|string. Updatedprocess()to route unmatched config-level ignores to a$warningsarray whenreportUnmatched === 'warning'src/Analyser/Ignore/IgnoredErrorHelperProcessedResult.php: Added$warningsconstructor parameter andgetWarnings()methodsrc/Analyser/AnalyserResultFinalizer.php: Changed type tobool|string. UpdatedaddUnmatchedIgnoredErrors()to route unmatched line-level ignores to warningssrc/Analyser/FinalizerResult.php: Added$warningsconstructor parameter andgetWarnings()methodsrc/Command/AnalyseApplication.php: Merged warnings fromFinalizerResultandIgnoredErrorHelperProcessedResultintoAnalysisResultsrc/DependencyInjection/ValidateIgnoredErrorsExtension.php: Updated to validate paths when setting is'warning'(not justtrue)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 issuereportUnmatched: Extended to also accept'warning', including proper merge logic during deduplicationRoot cause
The
reportUnmatchedIgnoredErrorssetting only supportedtrue/false. Users who wanted to see unmatched baseline entries without failing the build had to temporarily change this tofalsebefore 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 patternstestReportUnmatchedIgnoredErrorsWarningPerError: Verifies per-errorreportUnmatched: 'warning'produces warningstestReportUnmatchedIgnoredErrorsWarningPerErrorRaw: Same forrawMessagepatternstestReportUnmatchedIgnoredErrorsWarningLine: Verifies'warning'setting produces warnings for unmatched@phpstan-ignoreline commentsFixes phpstan/phpstan#9695