Suggest comment on const block for uncommented exported consts.
diff --git a/lint.go b/lint.go
index c06d5bd..add19b9 100644
--- a/lint.go
+++ b/lint.go
@@ -493,7 +493,11 @@
if vs.Doc == nil {
if gd.Doc == nil && !genDeclMissingComments[gd] {
- f.errorf(vs, 1, "exported %s %s should have comment or be unexported", kind, name)
+ block := ""
+ if kind == "const" && gd.Lparen.IsValid() {
+ block = " (or a comment on this block)"
+ }
+ f.errorf(vs, 1, "exported %s %s should have comment%s or be unexported", kind, name, block)
genDeclMissingComments[gd] = true
}
return
diff --git a/testdata/const-block.go b/testdata/const-block.go
index 04ad90d..4b89d6f 100644
--- a/testdata/const-block.go
+++ b/testdata/const-block.go
@@ -8,7 +8,7 @@
// MATCH /InlineWhatever.*form/
InlineWhatever = "blah"
- Whatsit = "missing_comment" // MATCH /Whatsit.*should have comment/
+ Whatsit = "missing_comment" // MATCH /Whatsit.*should have comment.*block/
// We should only warn once per block for missing comments,
// but always complain about malformed comments.
@@ -26,3 +26,11 @@
Beta = "b"
Gamma = "g"
)
+
+// The comment on the previous const block shouldn't flow through to here.
+
+const UndocAgain = 6 // MATCH /UndocAgain.*should have comment/
+
+const (
+ SomeUndocumented = 7 // MATCH /SomeUndocumented.*should have comment.*block/
+)