From bf6a99cf2323c08c8ae652b3a151ab766d1f9a1d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Oct 2026 14:57:47 +0200 Subject: [PATCH] Fix blink spacing for new Enum() and yield from () to match ECS --- blink/internal/fixer/rules/constructs.go | 13 ++++++++++--- blink/internal/fixer/rules/rules_test.go | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/blink/internal/fixer/rules/constructs.go b/blink/internal/fixer/rules/constructs.go index 1137602b12..50fde271fa 100644 --- a/blink/internal/fixer/rules/constructs.go +++ b/blink/internal/fixer/rules/constructs.go @@ -168,10 +168,11 @@ func (f SingleSpaceAroundConstruct) Fix(s *tokens.Stream) bool { continue } next := s.At(i + 1) - // "static" and "class" directly before "(" are a class reference, not a - // construct: "new static(...)", "new class(...)". They take no space. + // "static", "class" and "enum" directly before "(" are a class reference, + // not a construct: "new static(...)", "new class(...)", "new Enum(...)". + // They take no space ("enum" never opens a "(" as a declaration keyword). kw := strings.ToLower(t.Value) - classRef := kw == "static" || kw == "class" + classRef := kw == "static" || kw == "class" || kw == "enum" if next.Kind == token.Whitespace { if classRef && !hasNewline(next.Value) && i+2 < s.Len() && s.At(i+2).Kind == token.Punct && s.At(i+2).Value == "(" { @@ -226,6 +227,12 @@ func (NoSpacesAfterFunctionName) Fix(s *tokens.Stream) bool { if s.At(i).Kind != token.Ident { continue } + // "from" in "yield from (expr)" is part of the construct, not a call + if strings.EqualFold(s.At(i).Value, "from") { + if p := sigPrev(s, i); p >= 0 && s.At(p).Kind == token.Keyword && strings.EqualFold(s.At(p).Value, "yield") { + continue + } + } if i+2 < s.Len() && s.At(i+1).Kind == token.Whitespace && !hasNewline(s.At(i+1).Value) && s.At(i+2).Kind == token.Punct && s.At(i+2).Value == "(" { diff --git a/blink/internal/fixer/rules/rules_test.go b/blink/internal/fixer/rules/rules_test.go index 40d4a35097..e937274a77 100644 --- a/blink/internal/fixer/rules/rules_test.go +++ b/blink/internal/fixer/rules/rules_test.go @@ -172,6 +172,15 @@ func TestSingleSpaceAroundConstruct(t *testing.T) { if _, changed := apply(t, SingleSpaceAroundConstruct{}, "all(); }"); changed { + t.Fatal("yield from ( must keep its space") + } } func TestNoSpacesInsideParenthesis(t *testing.T) {