@@ -182,7 +182,7 @@ func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) {
182
182
return
183
183
}
184
184
185
- if ! hasTextComment (fn .Doc ) {
185
+ if ! hasDocComment (fn .Doc ) {
186
186
w .onFailure (lint.Failure {
187
187
Node : fn ,
188
188
Confidence : 1 ,
@@ -247,7 +247,7 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) {
247
247
return
248
248
}
249
249
250
- if ! hasTextComment (doc ) {
250
+ if ! hasDocComment (doc ) {
251
251
w .onFailure (lint.Failure {
252
252
Node : t ,
253
253
Confidence : 1 ,
@@ -314,7 +314,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
314
314
return
315
315
}
316
316
317
- if ! hasTextComment (vs .Doc ) && ! hasTextComment (gd .Doc ) {
317
+ if ! hasDocComment (vs .Doc ) && ! hasDocComment (gd .Doc ) {
318
318
if genDeclMissingComments [gd ] {
319
319
return
320
320
}
@@ -332,16 +332,16 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
332
332
return
333
333
}
334
334
// If this GenDecl has parens and a comment, we don't check its comment form.
335
- if hasTextComment (gd .Doc ) && gd .Lparen .IsValid () {
335
+ if hasDocComment (gd .Doc ) && gd .Lparen .IsValid () {
336
336
return
337
337
}
338
338
// The relevant text to check will be on either vs.Doc or gd.Doc.
339
339
// Use vs.Doc preferentially.
340
340
var doc * ast.CommentGroup
341
341
switch {
342
- case hasTextComment (vs .Doc ):
342
+ case hasDocComment (vs .Doc ):
343
343
doc = vs .Doc
344
- case hasTextComment (vs .Comment ) && ! hasTextComment (gd .Doc ):
344
+ case hasDocComment (vs .Comment ) && ! hasDocComment (gd .Doc ):
345
345
doc = vs .Comment
346
346
default :
347
347
doc = gd .Doc
@@ -359,17 +359,26 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
359
359
}
360
360
}
361
361
362
- // hasTextComment returns true if the comment contains a text comment
362
+ // hasDocComment reports whether the comment group contains a documentation comment,
363
+ // excluding directive comments and those consisting solely of a deprecation notice.
363
364
// e.g. //go:embed foo.txt a directive comment, not a text comment
364
365
// e.g. //nolint:whatever is a directive comment, not a text comment
365
- func hasTextComment (comment * ast.CommentGroup ) bool {
366
+ // e.g. // Deprecated: this is a deprecation comment
367
+ func hasDocComment (comment * ast.CommentGroup ) bool {
366
368
if comment == nil {
367
369
return false
368
370
}
369
371
370
372
// a comment could be directive and not a text comment
371
- text := comment .Text ()
372
- return text != ""
373
+ text := comment .Text () // removes directives from the comment block
374
+ return text != "" && ! isOnlyDeprecationComment (text )
375
+ }
376
+
377
+ // isOnlyDeprecationComment returns true if the comment starts with a standard deprecation notice.
378
+ // It considers all paragraphs following the deprecation notice as part of the deprecation comment.
379
+ // Assumes the comment is following the general ordering convention: (doc comment + deprecation)
380
+ func isOnlyDeprecationComment (comment string ) bool {
381
+ return strings .HasPrefix (comment , "Deprecated: " )
373
382
}
374
383
375
384
// normalizeText is a helper function that normalizes comment strings by:
@@ -401,7 +410,7 @@ func (w *lintExported) Visit(n ast.Node) ast.Visitor {
401
410
case * ast.TypeSpec :
402
411
// inside a GenDecl, which usually has the doc
403
412
doc := v .Doc
404
- if ! hasTextComment (doc ) {
413
+ if ! hasDocComment (doc ) {
405
414
doc = w .lastGen .Doc
406
415
}
407
416
w .lintTypeDoc (v , doc )
@@ -437,7 +446,7 @@ func (w *lintExported) lintInterfaceMethod(typeName string, m *ast.Field) {
437
446
return
438
447
}
439
448
name := m .Names [0 ].Name
440
- if ! hasTextComment (m .Doc ) {
449
+ if ! hasDocComment (m .Doc ) {
441
450
w .onFailure (lint.Failure {
442
451
Node : m ,
443
452
Confidence : 1 ,
0 commit comments