From fc4f2c050ef4ed7c373237fb5852ea799365bcd3 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 11 Nov 2026 13:39:41 +0000 Subject: [PATCH] Blink: skip destructuring targets in `LineLength` Symplify's `LineLengthFixer` only processes array literals: a short destructuring target (`[$a, $b] = ...`, `foreach (... as [...])`) is a different token kind in PHP-CS-Fixer, so the PHP engine never breaks or inlines it. The Go port treated any short `[` as an array and broke over-long destructuring targets across lines. Skip them the same way. Co-Authored-By: Claude Opus 5.5 --- blink/internal/fixer/rules/line_length.go | 5 +++- .../rules/line_length_destructuring_test.go | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 blink/internal/fixer/rules/line_length_destructuring_test.go diff --git a/blink/internal/fixer/rules/line_length.go b/blink/internal/fixer/rules/line_length.go index 0c3883c507..3381359337 100644 --- a/blink/internal/fixer/rules/line_length.go +++ b/blink/internal/fixer/rules/line_length.go @@ -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 } diff --git a/blink/internal/fixer/rules/line_length_destructuring_test.go b/blink/internal/fixer/rules/line_length_destructuring_test.go new file mode 100644 index 0000000000..849588e594 --- /dev/null +++ b/blink/internal/fixer/rules/line_length_destructuring_test.go @@ -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": " [" + items + "]) {\n}\n", + "nested": "