Skip to content
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

stylecheck: package comment should at least have a valid package comment #871

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion stylecheck/lint.go
Expand Up @@ -42,7 +42,15 @@ func CheckPackageComment(pass *analysis.Pass) (interface{}, error) {
if pass.Pkg.Name() == "main" {
return nil, nil
}

type invalidDoc struct {
doc *ast.CommentGroup
msg string
}
var invalidDocs []invalidDoc
hasDocs := false
hasValidDoc := false

for _, f := range pass.Files {
if code.IsInTest(pass, f) {
continue
Expand All @@ -51,11 +59,19 @@ func CheckPackageComment(pass *analysis.Pass) (interface{}, error) {
hasDocs = true
prefix := "Package " + f.Name.Name + " "
if !strings.HasPrefix(strings.TrimSpace(f.Doc.Text()), prefix) {
report.Report(pass, f.Doc, fmt.Sprintf(`package comment should be of the form "%s..."`, prefix))
invalidDocs = append(invalidDocs, invalidDoc{doc: f.Doc, msg: fmt.Sprintf(`package comment should be of the form "%s..."`, prefix)})
} else {
hasValidDoc = true
}
}
}

if !hasValidDoc {
for _, i := range invalidDocs {
report.Report(pass, i.doc, i.msg)
}
}

if !hasDocs {
for _, f := range pass.Files {
if code.IsInTest(pass, f) {
Expand Down