1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
This commit is contained in:
chavacava 2022-06-28 17:14:26 +02:00 committed by GitHub
parent 3f9c0c2175
commit 2aac974b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 11 deletions

View File

@ -251,7 +251,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
return
}
if vs.Doc == nil && gd.Doc == nil {
if vs.Doc == nil && vs.Comment == nil && gd.Doc == nil {
if genDeclMissingComments[gd] {
return
}
@ -274,10 +274,16 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
}
// The relevant text to check will be on either vs.Doc or gd.Doc.
// Use vs.Doc preferentially.
doc := vs.Doc
if doc == nil {
var doc *ast.CommentGroup
switch {
case vs.Doc != nil:
doc = vs.Doc
case vs.Comment != nil && gd.Doc == nil:
doc = vs.Comment
default:
doc = gd.Doc
}
prefix := name + " "
s := normalizeText(doc.Text())
if !strings.HasPrefix(s, prefix) {

View File

@ -4,11 +4,14 @@
package foo
const (
InlineComment = "ShouldBeOK" // InlineComment is a valid comment
// Prefix for something.
// MATCH /comment on exported const InlineWhatever should be of the form "InlineWhatever ..."/
InlineWhatever = "blah"
Whatsit = "missing_comment" // MATCH /exported const Whatsit should have comment (or a comment on this block) or be unexported/
Whatsit = "missing_comment"
// MATCH:13 /exported const Whatsit should have comment (or a comment on this block) or be unexported/
// We should only warn once per block for missing comments,
// but always complain about malformed comments.
@ -29,8 +32,11 @@ const (
// The comment on the previous const block shouldn't flow through to here.
const UndocAgain = 6 // MATCH /exported const UndocAgain should have comment or be unexported/
const UndocAgain = 6
// MATCH:35 /exported const UndocAgain should have comment or be unexported/
const (
SomeUndocumented = 7 // MATCH /exported const SomeUndocumented should have comment (or a comment on this block) or be unexported/
SomeUndocumented = 7
// MATCH:40 /exported const SomeUndocumented should have comment (or a comment on this block) or be unexported/
)

View File

@ -11,7 +11,9 @@ import (
var unexp = errors.New("some unexported error") // MATCH /error var unexp should have name of the form errFoo/
// Exp ...
var Exp = errors.New("some exported error") // MATCH /error var Exp should have name of the form ErrFoo/
var Exp = errors.New("some exported error")
// MATCH:14 /error var Exp should have name of the form ErrFoo/
var (
e1 = fmt.Errorf("blah %d", 4) // MATCH /error var e1 should have name of the form errFoo/

View File

@ -24,15 +24,22 @@ type V string
func (*V) H() {} // MATCH /exported method V.H should have comment or be unexported/
var W = "foo" // MATCH /exported var W should have comment or be unexported/
var W = "foo"
const X = "bar" // MATCH /exported const X should have comment or be unexported/
// MATCH:27 /exported var W should have comment or be unexported/
var Y, Z int // MATCH /exported var Z should have its own declaration/
const X = "bar"
// MATCH:31 /exported const X should have comment or be unexported/
var Y, Z int
// MATCH:35 /exported var Z should have its own declaration/
// Location should be okay, since the other var name is an underscore.
var Location, _ = time.LoadLocation("Europe/Istanbul") // not Constantinople
// this is improperly documented
// MATCH /comment on exported const Thing should be of the form "Thing ..."/
const Thing = "wonderful"
// MATCH:42 /comment on exported const Thing should be of the form "Thing ..."/