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
2 changes: 1 addition & 1 deletion .github/workflows/blink_parity_mautic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- name: Compare the two trees
run: |
# ratchet gate: fail once the differing share crosses this; lower it as parity improves
MAX_DIFF_PERCENT=0.6
MAX_DIFF_PERCENT=0.5
total=0
differ=0
differing_files=""
Expand Down
15 changes: 14 additions & 1 deletion blink/internal/fixer/rules/method_argument_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func reflowMultilineArgs(s *tokens.Stream) bool {
if closeIdx < 0 || !argListIsMultiline(s, open, closeIdx) {
continue
}
if !isCallOrDeclParen(s, open) {
if !isCallOrDeclParen(s, open) && !isGroupingReflowParen(s, open) {
continue
}
if sigNext(s, open) == closeIdx {
Expand All @@ -416,6 +416,19 @@ func reflowMultilineArgs(s *tokens.Stream) bool {
return changed
}

// isGroupingReflowParen reports whether the "(" at open is a grouping parenthesis
// after a boolean operator ("!(", "&& (", "|| ("). php-cs-fixer's MethodArgumentSpace
// processes such parens like an argument list and, when multiline, breaks the first
// operand onto its own line.
func isGroupingReflowParen(s *tokens.Stream, open int) bool {
p := sigPrev(s, open)
if p < 0 {
return false
}
t := s.At(p)
return t.Kind == token.Punct && (t.Value == "!" || t.Value == "&&" || t.Value == "||")
}

// isAttributeComment reports whether t is a "#[...]" attribute (the lexer keeps
// it as one comment token), as opposed to a "//" or "#" line comment.
func isAttributeComment(t token.Token) bool {
Expand Down
4 changes: 4 additions & 0 deletions blink/internal/fixer/rules/method_argument_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func TestMethodArgumentSpace(t *testing.T) {
{"newline only inside a nested arg is left alone", "<?php foo($a, [\n 1,\n]);", "<?php foo($a, [\n 1,\n]);", false},
{"trailing comma before paren", "<?php foo($a,);", "<?php foo($a, );", true},
{"blank line between multiline args is preserved", "<?php foo(\n $a,\n\n $b\n);", "<?php foo(\n $a,\n\n $b\n);", false},
{"grouping paren after ! breaks after (", "<?php return !($a\n|| $b\n);", "<?php return !(\n $a\n|| $b\n);", true},
{"grouping paren after && breaks after (", "<?php $x = $a && ($b\n|| $c\n);", "<?php $x = $a && (\n $b\n|| $c\n);", true},
{"single-line grouping paren left alone", "<?php return !($a || $b);", "<?php return !($a || $b);", false},
{"control-structure paren is not reflowed", "<?php if ($a\n|| $b\n) {}", "<?php if ($a\n|| $b\n) {}", false},
}

for _, tc := range cases {
Expand Down
Loading