Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion stylecheck/lint.go
Original file line number Diff line number Diff line change
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