Skip to content

Fix blink YodaStyle swapping parenthesized assignment after OperatorLinebreak - #226

Merged
TomasVotruba merged 2 commits into
mainfrom
blink-yoda-paren-assignment-fix
Oct 27, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
blink-yoda-paren-assignment-fix

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Problem

On the laravel parity corpus, blink diverged from PHP ECS on src/Illuminate/Auth/Access/Gate.php (and others):

PHP ECS: && null !== ($policy = $this->getPolicyFor($arguments[0]))
blink:   && ($policy = $this->getPolicyFor($arguments[0])) !== null

Root cause

OperatorLinebreak, when moving a boolean operator to the next line, blanked the operator tokens with SetValue("") but left them in the stream. Those zero-width Punct tokens then extended YodaStyle's operand scan past the closing paren, defeating the guard that keeps a whole parenthesized group in place. As a result a parenthesized assignment null !== ($p = ...) was wrongly swapped to ($p = ...) !== null.

The bug only surfaced in the full pipeline (IsNull -> OperatorLinebreak -> YodaStyle) with the operator moved to line start, which is why isolated fixer tests passed.

Fix

Drop the blanked tokens after moving operators. The change is render-neutral (zero-width tokens produce no output), so it can only remove latent corruption, not alter correct output. The idempotency test confirms this.

Verification

  • Full blink Go test suite + go vet + gofmt pass; added a regression test.
  • laravel parity: 48 -> 45 differing files, zero regressions.

Also adds phase-progress logging to blink/parity/run.sh so the parity CI step is no longer silent during the long fix phase.

…daStyle

Moving a boolean operator to the next line blanked the operator tokens
with SetValue("") but left them in the stream. The zero-width Punct
tokens extended YodaStyle's operand scan past a closing paren, so a
parenthesized assignment "null !== ($p = ...)" was wrongly swapped to
"($p = ...) !== null", diverging from PHP ECS (laravel Gate.php).

Drop the blanked tokens after moving operators. Adds a regression test
and phase progress output to the parity harness.
@TomasVotruba
TomasVotruba merged commit 50f0038 into main Oct 27, 2026
21 checks passed
@TomasVotruba
TomasVotruba deleted the blink-yoda-paren-assignment-fix branch October 27, 2026 08:55
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