Skip to content

Blink parity: break outer list opener for nested arrays; gate to 0.6% - #135

Open
TomasVotruba wants to merge 2 commits into
mainfrom
tv-blink-parity-next
Open

TomasVotruba wants to merge 2 commits into
mainfrom
tv-blink-parity-next

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Cracks the largest remaining mautic parity cluster. Measured drop: 36 to 25 differing files of 4527 (0.55%), 11 files fixed with zero regressions.

The cluster

A single-line list array whose last element is an associative array:

return [$notifications, $showNewIndicator, ['isNew' => $x, 'message' => $y]];

ECS expands the nested associative array and then also breaks the outer list opener onto its own line:

return [
    $notifications, $showNewIndicator, [
        'isNew' => $x,
        'message' => $y,
    ]];

blink previously broke only the nested array and left the outer opener inline.

Root cause

The outer break is an emergent position-staleness effect in ECS's ArrayOpenerAndCloserNewlineFixer: expanding the nested associative array shifts the enclosing list's stored end position, so the opener is later evaluated against a stale end that lands inside the nested array (which carries =>), while the closer was evaluated before the shift. Opener breaks, closer does not.

The fix

Implemented in ArrayListItemNewline (it runs first and fully expands the nested array before ArrayOpenerAndCloserNewline sees it, so the "was single-line?" signal only exists here). When it expands a pristine single-line associative array that is the last element of an enclosing list (first element not an array, opener not already broken), it also breaks the list's opener. An already-multiline inner array takes a different branch and the outer is left alone, matching ECS.

Gate

MAX_DIFF_PERCENT lowered 0.8 to 0.6; actual is 0.55% (25 of 4527).

Unit tests cover the outer-opener break and the already-multiline no-break case. Full blink suite, go vet and golangci-lint green; strict rector-src 1:1 gate stays 0-diff.

When ArrayListItemNewline expands a single-line associative array that is the
last element of an enclosing list array, it now also puts the list's opener on
its own line, matching ECS. Upstream, ArrayOpenerAndCloserNewline expands the
nested array with two inserts that shift the list's stored end position, so it
treats the list as indexed when placing the opener (but not the earlier-run
closer); an already-multiline nested array shifts nothing and is left alone.
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.

1 participant