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
6 changes: 4 additions & 2 deletions blink/internal/fixer/rules/symplify_docblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)`)
)

Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions blink/internal/fixer/rules/symplify_docblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "<?php\nclass A {\n /**\n * Matches only \"@type\" at the start of a line\n */\n public $x;\n}\n"
if got, changed := apply(t, TypeToVarTag{}, src); changed || got != src {
t.Fatalf("@type in a description must not change: %q", got)
}
}

// TestMergeDocBlockStart folds an empty leading line into the /** opener.
func TestMergeDocBlockStart(t *testing.T) {
got, changed := apply(t, MergeDocBlockStart{}, "<?php\nclass A {\n /*\n *\n * @var int\n */\n private $x;\n}\n")
Expand Down
Loading