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
5 changes: 4 additions & 1 deletion blink/internal/fixer/rules/line_length.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func (f LineLength) Fix(s *tokens.Stream) bool {
if f.processOpener(s, pos) {
changed = true
}
case t.Kind == token.Punct && t.Value == "]" && llIsArrayClose(s, pos):
// like Symplify, only array literals: a destructuring target ("[$a, $b] =",
// "foreach (... as [...])") is a different token kind there and is skipped
case t.Kind == token.Punct && t.Value == "]" && llIsArrayClose(s, pos) &&
!arrayNotationIsDestructuring(s, s.MatchBackward(pos)):
if f.processArrayClose(s, pos) {
changed = true
}
Expand Down
27 changes: 27 additions & 0 deletions blink/internal/fixer/rules/line_length_destructuring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package rules

import "testing"

// Symplify's LineLengthFixer only processes array literals, so an over-long
// destructuring target is left alone while an array literal is still broken.
// Expectations are the PHP fixer's own output.
func TestLineLengthSkipsDestructuring(t *testing.T) {
t.Parallel()
const items = "$aaaaaaaaaaaaaaaaaaaa, $bbbbbbbbbbbbbbbbbbbbbbbb, $cccccccccccccccccccccccc, $dddddddddddddddddddddd, $eeeeeeeeeeee"
for name, src := range map[string]string{
"assignment": "<?php\n[" + items + "] = foo();\n",
"foreach": "<?php\nforeach ($rows as [" + items + "]) {\n}\n",
"foreach key": "<?php\nforeach ($rows as $key => [" + items + "]) {\n}\n",
"nested": "<?php\n[[" + items + "], $f] = foo();\n",
} {
if got, changed := apply(t, LineLength{}, src); changed {
t.Errorf("%s must not change, got %q", name, got)
}
}

got, _ := apply(t, LineLength{}, "<?php\n$x = ["+items+"];\n")
want := "<?php\n$x = [\n $aaaaaaaaaaaaaaaaaaaa,\n $bbbbbbbbbbbbbbbbbbbbbbbb,\n $cccccccccccccccccccccccc,\n $dddddddddddddddddddddd,\n $eeeeeeeeeeee\n];\n"
if got != want {
t.Errorf("array literal:\n got %q\nwant %q", got, want)
}
}
Loading