Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions blink/internal/fixer/rules/yoda_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
"+=", "-=", "*=", "/=", ".=", "%=", "**=", "??=", "&=", "|=", "^=", "<<=", ">>=":
Expand Down
2 changes: 1 addition & 1 deletion blink/internal/fixer/rules/yoda_style_phpcsfixer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions blink/internal/fixer/rules/yoda_style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ func TestYodaStyle(t *testing.T) {
// match-arm condition (=> boundary) is de-yoda'd too
assertFix(t, f, "<?php\n$r = match (true) {\n null !== $x => 1,\n};", "<?php\n$r = match (true) {\n $x !== null => 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,
"<?php\nif ($a) {\n $b = 1;\n}\n\nnull === $delay\n ? x()\n : y($delay);",
"<?php\nif ($a) {\n $b = 1;\n}\n\n$delay === null\n ? x()\n : y($delay);",
true)

// already non-yoda - no-op
assertFix(t, f, "<?php\nif ($x === null) {}", "<?php\nif ($x === null) {}", false)

Expand Down
Loading