From 24ad10e6ea0527663463af5d402842c71bbcefdd Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 30 Oct 2026 17:34:47 +0100 Subject: [PATCH] Fix blink YodaStyle skipping a comparison that follows a block's closing brace --- blink/internal/fixer/rules/yoda_style.go | 6 ++++-- blink/internal/fixer/rules/yoda_style_phpcsfixer_test.go | 2 +- blink/internal/fixer/rules/yoda_style_test.go | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/blink/internal/fixer/rules/yoda_style.go b/blink/internal/fixer/rules/yoda_style.go index 4510790e60..eedf1c0a38 100644 --- a/blink/internal/fixer/rules/yoda_style.go +++ b/blink/internal/fixer/rules/yoda_style.go @@ -460,8 +460,10 @@ func isLeftBoundary(s *tokens.Stream, p int) bool { if t.Kind == token.Punct { switch t.Value { // "." (concat) binds tighter than comparison, so an operand next to it is - // part of a larger concat expression, not a standalone comparison operand - case "(", "[", "{", ",", ";", "&&", "||", "?", "??", ":", "=", "!", "=>", + // part of a larger concat expression, not a standalone comparison operand. + // "}" closes a preceding block (e.g. "if {...}"), so a literal right after it + // starts a new statement and is a standalone comparison operand + case "(", "[", "{", "}", ",", ";", "&&", "||", "?", "??", ":", "=", "!", "=>", // compound assignments bind looser than a comparison, so the operand // after one is a standalone comparison operand ("$x += C === $y") "+=", "-=", "*=", "/=", ".=", "%=", "**=", "??=", "&=", "|=", "^=", "<<=", ">>=": diff --git a/blink/internal/fixer/rules/yoda_style_phpcsfixer_test.go b/blink/internal/fixer/rules/yoda_style_phpcsfixer_test.go index 24727fddd6..c185329b5c 100644 --- a/blink/internal/fixer/rules/yoda_style_phpcsfixer_test.go +++ b/blink/internal/fixer/rules/yoda_style_phpcsfixer_test.go @@ -470,7 +470,7 @@ var yodaKnownFailures = map[string]bool{ "yoda#38": true, "yoda#40": true, "yoda#42": true, "yoda#44": true, "yoda#46": true, "yoda#47": true, "yoda#50": true, "yoda#136": true, "yoda#137": true, "yoda#144": true, "yoda#148": true, "yoda#150": true, "yoda#152": true, "yoda#156": true, "yoda#158": true, "yoda#160": true, "yoda#162": true, "yoda#164": true, "yoda#168": true, "yoda#169": true, "yoda#170": true, "yoda#171": true, - "yoda#174": true, "yoda#176": true, "yoda#178": true, "yoda#179": true, "yoda#180": true, "yoda#181": true, "yoda#182": true, "yoda#183": true, + "yoda#174": true, "yoda#176": true, "yoda#186": true, "yoda#187": true, "yoda#188": true, "yoda#189": true, "yoda#192": true, "yoda#193": true, "yoda#194": true, "yoda#195": true, "yoda#196": true, "yoda#197": true, "yoda#198": true, "yoda#199": true, "yoda#200": true, "yoda#201": true, "yoda#202": true, "yoda#203": true, "yoda#204": true, "yoda#205": true, "yoda#206": true, "yoda#207": true, "yoda#208": true, "yoda#209": true, "yoda#210": true, "yoda#211": true, diff --git a/blink/internal/fixer/rules/yoda_style_test.go b/blink/internal/fixer/rules/yoda_style_test.go index 5740bd8ff1..e8ec207d16 100644 --- a/blink/internal/fixer/rules/yoda_style_test.go +++ b/blink/internal/fixer/rules/yoda_style_test.go @@ -42,6 +42,13 @@ func TestYodaStyle(t *testing.T) { // match-arm condition (=> boundary) is de-yoda'd too assertFix(t, f, " 1,\n};", " 1,\n};", true) + // comparison that is a multiline ternary condition starting right after a + // preceding block's "}" - the "}" is a left boundary, so it is de-yoda'd + assertFix(t, f, + "