diff --git a/rule/package-comments.go b/rule/package-comments.go index 02f246be0..f1e5462fe 100644 --- a/rule/package-comments.go +++ b/rule/package-comments.go @@ -150,17 +150,9 @@ func (l *lintPackageComments) Visit(_ ast.Node) ast.Visitor { return nil } s := l.fileAst.Doc.Text() - if ts := strings.TrimLeft(s, " \t"); ts != s { - l.onFailure(lint.Failure{ - Category: "comments", - Node: l.fileAst.Doc, - Confidence: 1, - Failure: "package comment should not have leading space", - }) - s = ts - } + // Only non-main packages need to keep to this form. - if !l.file.Pkg.IsMain() && !strings.HasPrefix(s, prefix) { + if !l.file.Pkg.IsMain() && !strings.HasPrefix(s, prefix) && !isDirectiveComment(s) { l.onFailure(lint.Failure{ Category: "comments", Node: l.fileAst.Doc, diff --git a/testdata/golint/package-doc4.go b/testdata/golint/package-doc4.go deleted file mode 100644 index bf32cb9f4..000000000 --- a/testdata/golint/package-doc4.go +++ /dev/null @@ -1,7 +0,0 @@ -// Test of block package comment with leading space. - -/* - Package foo is pretty sweet. -MATCH /package comment should not have leading space/ -*/ -package foo diff --git a/testdata/golint/package-doc6.go b/testdata/golint/package-doc6.go new file mode 100644 index 000000000..918cbd115 --- /dev/null +++ b/testdata/golint/package-doc6.go @@ -0,0 +1,5 @@ +//revive:disable +//nolint:dupl,revive // looks the same but isn't +//revive:enable + +package foo // MATCH /should have a package comment/