-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive "should have a package comment" from golint #1556
Comments
Hello, golint is package-aware but the linting applies at file level. func (f *file) lintPackageComment()func (f *file) lintPackageComment() {
// ...
if f.f.Doc == nil {
f.errorf(f.f, 0.2, link(ref), category("comments"), "should have a package comment, unless it's in another file for this package")
return
}
// ...
} func (f *file) lint()func (f *file) lint() {
f.lintPackageComment()
// ...
} func (p *pkg) lint() []Problemfunc (p *pkg) lint() []Problem {
// ...
for _, f := range p.files {
f.lint()
}
/ ...
} func (f *file) errorf(...)func (f *file) errorf(n ast.Node, confidence float64, args ...interface{}) *Problem {
pos := f.fset.Position(n.Pos())
if pos.Filename == "" {
pos.Filename = f.filename
}
return f.pkg.errorfAt(pos, confidence, args...)
} Knowing that golint can only display errors at the file level, it is not possible to display a message related to a package. Furthermore, it is not possible to know which file in a package should contain the package comment. |
The default So by default, those messages are not displayed by golint. golangci-lint/pkg/commands/run.go Line 139 in 0370d3a
|
IMHO the |
Should we investigate whether it is possible to make AFAIK |
$ grep "f.errorf(" lint.go
f.errorf(f.f, 0.2, link(ref), category("comments"), "should have a package comment, unless it's in another file for this package")
f.errorf(f.f.Doc, 1, link(ref), category("comments"), "package comment should not have leading space")
f.errorf(f.f.Doc, 1, link(ref), category("comments"), `package comment should be of the form "%s..."`, prefix)
f.errorf(imp, 1, link(ref), category("imports"), "a blank import should be only in a main or test package, or have a comment justifying it")
f.errorf(is, 1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports")
f.errorf(f.f, 1, link("http://golang.org/doc/effective_go.html#package-names"), category("naming"), "don't use an underscore in package name")
f.errorf(f.f, 1, link("http://golang.org/doc/effective_go.html#package-names"), category("mixed-caps"), "don't use MixedCaps in package name; %s should be %s", f.f.Name.Name, strings.ToLower(f.f.Name.Name))
f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use ALL_CAPS in Go names; use CamelCase")
f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use leading k in Go names; %s %s should be %s", thing, id.Name, should)
f.errorf(id, 0.9, link("http://golang.org/doc/effective_go.html#mixed-caps"), category("naming"), "don't use underscores in Go names; %s %s should be %s", thing, id.Name, should)
f.errorf(id, 0.8, link(styleGuideBase+"#initialisms"), category("naming"), "%s %s should be %s", thing, id.Name, should)
f.errorf(t, 1, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name)
f.errorf(doc, 1, link(docCommentsLink), category("comments"), `comment on exported type %v should be of the form "%v ..." (with optional leading article)`, t.Name, t.Name)
f.errorf(fn, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment or be unexported", kind, name)
f.errorf(fn.Doc, 1, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
f.errorf(vs, 1, category("comments"), "exported %s %s should have its own declaration", kind, n.Name)
f.errorf(vs, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment%s or be unexported", kind, name, block)
f.errorf(doc, 1, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
f.errorf(id, 0.8, link(styleGuideBase+"#package-names"), category("naming"), "%s name will be used as %s.%s by other packages, and that stutters; consider calling this %s", thing, pkg, name, rem)
f.errorf(ifStmt.Else, 1, link(styleGuideBase+"#indent-error-flow"), category("indent"), "if block ends with a return statement, so drop this else and outdent its block"+extra)
p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for range ...`")
p := f.errorf(rs.Value, 1, category("range-loop"), "should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", f.render(rs.Key), rs.Tok)
p := f.errorf(node, 1, category("errors"), "should replace %s(fmt.Sprintf(...)) with %s.Errorf(...)", f.render(se), errorfPrefix)
f.errorf(id, 0.9, category("naming"), "error var %s should have name of the form %sFoo", id.Name, prefix)
f.errorf(str, conf, link(styleGuideBase+"#error-strings"), category("errors"),
f.errorf(n, 1, link(ref), category("naming"), `receiver name should not be an underscore, omit the name if it is unused`)
f.errorf(n, 1, link(ref), category("naming"), `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`)
f.errorf(n, 1, link(ref), category("naming"), "receiver name %s should be consistent with previous receiver name %s for %s", name, prev, recv)
f.errorf(as, 0.8, category("unary-op"), "should replace %s with %s%s", f.render(as), f.render(as.Lhs[0]), suffix)
f.errorf(fn, 0.9, category("arg-order"), "error should be the last type when returning multiple items")
f.errorf(ret.Type, 0.8, category("unexported-type-in-api"),
f.errorf(v, 0.9, category("time"), "var %s is of type %v; don't use unit-specific suffix %q", name.Name, origTyp, suffix)
f.errorf(x, 1.0, category("context"), fmt.Sprintf("should not use basic type %s as key in context.WithValue", key.Type))
f.errorf(fn, 0.9, link("https://golang.org/pkg/context/"), category("arg-order"), "context.Context should be the first parameter of a function")
|
sorry yes EXC0002 is also about the other comment rules, so this rule cannot be dropped. |
But EXC0002 could be divided into 2 or 3 rules:
also in EXC0002 we can remove the package part. |
yes I think we could investigate. I think that the current golint code was not designed to do that. |
FYI stylecheck handle that rule by package instead of file:
|
The minimal confidence set to 0 causes golint to report false possitive message about package godoc. It can be disabled by changing the confidence. Message: "should have a package comment, unless it's in another file for this package (golint)" REF: golangci/golangci-lint#1556 (comment)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The minimal confidence set to 0 causes golint to report false possitive message about package godoc. It can be disabled by changing the confidence. Message: "should have a package comment, unless it's in another file for this package (golint)" REF: golangci/golangci-lint#1556 (comment)
The minimal confidence set to 0 causes golint to report false possitive message about package godoc. It can be disabled by changing the confidence. Message: "should have a package comment, unless it's in another file for this package (golint)" REF: golangci/golangci-lint#1556 (comment)
Having following config:
I'm getting an error for each file in package (expect one with actual documentation):
Looks like
golint
is not package-aware?Related: #456 #464
Update:
If
min-confidence: 0
is removed, those issues are not reported 🤔The text was updated successfully, but these errors were encountered: