Skip to content

[ax] Add per-line rule attribution to JSON output - #8448

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-json-line-attribution
Sep 3, 2026
Merged

[ax] Add per-line rule attribution to JSON output#8448
TomasVotruba merged 1 commit into
mainfrom
tv-json-line-attribution

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

The --output-format=json payload lists applied_rectors as 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 (RectorWithLineChange carries {rector_class, line}). Machine consumers (agents, editors, CI annotations) had to re-parse the raw diff blob to guess which rule touched which line.

What

Emit an additive changes array 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_rectors is kept unchanged - backward compatible, no consumer breaks.
  • changes reuses FileDiff::getRectorChanges(), which already holds the per-line data; only a getLine() getter was missing on RectorWithLineChange.

line is 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

  • New testReportShouldAttributeEachRectorToItsLine with a with_diffs.json fixture.
  • composer check-cs clean, existing JSON test still green.

@TomasVotruba
TomasVotruba force-pushed the tv-json-line-attribution branch from 4ab7159 to e08d14d Compare September 3, 2026 21:12
@TomasVotruba
TomasVotruba enabled auto-merge (squash) September 3, 2026 21:13
@TomasVotruba
TomasVotruba merged commit 6d22545 into main Sep 3, 2026
43 checks passed
@TomasVotruba
TomasVotruba deleted the tv-json-line-attribution branch September 3, 2026 21:14
@TomasVotruba TomasVotruba changed the title [ChangesReporting] Add per-line rule attribution to JSON output [ax] Add per-line rule attribution to JSON output Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant