[reporting] Report unused skips in JSON output too#8065
Merged
Conversation
JSON output forces VERBOSITY_QUIET, which silenced the unused-skips warning. Extract the computation into UnusedSkipResolver and surface it as an unused_skips key in the JSON payload, so editor/CI runs using --output-format=json see unused skips as well.
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.
Why
->reportUnusedSkips()reports skips that never matched, so you can clean up dead->withSkip()entries. It writes viaSymfonyStyle, but when--output-format=jsonis used,ProcessCommandforcesVERBOSITY_QUIETand the warning is silenced entirely. Editor/CI integrations typically run--dry-run --output-format=json, so unused skips never showed up there.What
Surface unused skips in the JSON payload too. The computation is extracted into a shared
UnusedSkipResolverservice, so console and JSON stay in sync.Example
Config:
Console output (already worked):
JSON output before -- unused skips silently missing:
{ "totals": { "changed_files": 1, "errors": 0 }, "file_diffs": [ ... ], "changed_files": [ "src/SomeClass.php" ] }JSON output after -- new
unused_skipskey:{ "totals": { "changed_files": 1, "errors": 0 }, "file_diffs": [ ... ], "changed_files": [ "src/SomeClass.php" ], "unused_skips": [ "Rector\\CodeQuality\\Rector\\FunctionLike\\SimplifyUselessVariableRector => /src/NeverMatches.php" ] }The key is added only when
reportUnusedSkips()is enabled and something is actually unused, so the JSON schema is otherwise untouched.Changes
src/Reporting/UnusedSkipResolver.php(new) -- single source of truth. Returns"rule => path"for rule-scoped skips and a plain path for global ones; honors thereportUnusedSkips()guard; keeps the existing rules (per-path granularity, rule-scoped masks kept, global masks excluded).src/Reporting/MissConfigurationReporter.php-- delegates to the resolver; console output unchanged.src/ChangesReporting/Output/JsonOutputFormatter.php-- injects the resolver, passes results to the factory.src/ChangesReporting/Output/Factory/JsonOutputFactory.php-- optional$unusedSkipsparam, adds theunused_skipskey when non-empty.Tests
UnusedSkipResolverTest(unit): rule-scoped unused skip reported asrule => path; matched / global-mask / skip-everywhere excluded; disabled returns empty.MissConfigurationReporterTestupdated to the new constructor.