Skip to content

Commit 0d1b87f

Browse files
committed
fix(doclink): fix issue where doclink could sometimes check the first line inside a function as if it was a top-level definition.
1 parent c047f0d commit 0d1b87f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

internal/cmd/tools/doclink/doclink.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ func processInternal(cfg config, file *os.File, pairs map[string]map[string]stri
390390
trimmedNextLine = nextLine
391391
}
392392

393-
// Check for new doc links to add
394-
if !inFunc && !inInterface && isValidDefinition(trimmedNextLine, &inGroup, &inStruct) {
393+
// Only check top-level definitions.
394+
// Example: on a line like "func f() {", inFunc is still false here.
395+
// Without the explicit func check, the next line could be treated like a top-level definition.
396+
if !inFunc && !inInterface && !strings.HasPrefix(trimmedLine, "func ") && isValidDefinition(trimmedNextLine, &inGroup, &inStruct) {
395397
// Find the "Exposed As" line in the doc comment
396398
var existingDoclink string
397399
comScanner := bufio.NewScanner(strings.NewReader(commentBlock))

0 commit comments

Comments
 (0)