diff --git a/blink/internal/fixer/rules/symplify_docblock.go b/blink/internal/fixer/rules/symplify_docblock.go index 8980782c48..fed20bea60 100644 --- a/blink/internal/fixer/rules/symplify_docblock.go +++ b/blink/internal/fixer/rules/symplify_docblock.go @@ -133,7 +133,9 @@ func (FixTagTypo) Fix(s *tokens.Stream) bool { type TypeToVarTag struct{} var ( - typeTagRe = regexp.MustCompile(`@type\b`) + // only "@type" at the start of a doc line (after an optional /**, /* or *), + // never inside a description - mirrors TypeToVarTagFixer #81 + typeTagRe = regexp.MustCompile(`(?m)^(\s*(?:/\*{1,2}|\*)?\s*)@type\b`) typeToVarSingleAsteriskRe = regexp.MustCompile(`^/\*(\n?\s+@var)`) ) @@ -155,7 +157,7 @@ func (TypeToVarTag) Fix(s *tokens.Stream) bool { if !typeTagRe.MatchString(t.Value) { continue } - nc := typeTagRe.ReplaceAllString(t.Value, "@var") + nc := typeTagRe.ReplaceAllString(t.Value, "${1}@var") nc = typeToVarSingleAsteriskRe.ReplaceAllString(nc, "/**$1") s.Set(i, token.Token{Kind: token.DocComment, Value: nc}) changed = true diff --git a/blink/internal/fixer/rules/symplify_docblock_test.go b/blink/internal/fixer/rules/symplify_docblock_test.go index 561dbac0e4..b2ebe0fa21 100644 --- a/blink/internal/fixer/rules/symplify_docblock_test.go +++ b/blink/internal/fixer/rules/symplify_docblock_test.go @@ -37,6 +37,15 @@ func TestTypeToVarTag(t *testing.T) { idempotent(t, TypeToVarTag{}, got) } +// TestTypeToVarTagSkipsDescription leaves "@type" inside a description untouched, +// only rewriting it at the start of a doc line (mirrors #81). +func TestTypeToVarTagSkipsDescription(t *testing.T) { + src := "