[ax] Add per-line rule attribution to JSON output - #8448
Merged
Conversation
TomasVotruba
force-pushed
the
tv-json-line-attribution
branch
from
September 3, 2026 21:12
4ab7159 to
e08d14d
Compare
TomasVotruba
enabled auto-merge (squash)
September 3, 2026 21:13
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
The
--output-format=jsonpayload listsapplied_rectorsas a flat, de-duplicated array of class strings per file. It drops the line each rule fired at - even though Rector already tracks it internally (RectorWithLineChangecarries{rector_class, line}). Machine consumers (agents, editors, CI annotations) had to re-parse the rawdiffblob to guess which rule touched which line.What
Emit an additive
changesarray on each file diff, pairing every rule application with its line:{ "file": "some/file.php", "diff": "--- Original\n+++ New\n@@ -38,5 +39,6 @@\n...", "applied_rectors": [ "Rector\\Php80\\Rector\\Identical\\StrEndsWithRector", "Rector\\Php80\\Rector\\Identical\\StrStartsWithRector" ], "changes": [ { "rector": "Rector\\Php80\\Rector\\Identical\\StrStartsWithRector", "line": 38 }, { "rector": "Rector\\Php80\\Rector\\Identical\\StrEndsWithRector", "line": 42 } ] }applied_rectorsis kept unchanged - backward compatible, no consumer breaks.changesreusesFileDiff::getRectorChanges(), which already holds the per-line data; only agetLine()getter was missing onRectorWithLineChange.lineis the node's source line when the rule fired, not the post-change hunk line - approximate but enough to jump to or group by rule. Structuring the diff into machine hunks is a larger, separate change.Tests
testReportShouldAttributeEachRectorToItsLinewith awith_diffs.jsonfixture.composer check-csclean, existing JSON test still green.