From 1f3b35ca1d564391aaaf57cd6c28cb8adceaf798 Mon Sep 17 00:00:00 2001 From: chavacava Date: Sat, 11 May 2024 20:05:38 +0200 Subject: [PATCH 1/2] removes spurious warning on package comments starting with spaces --- rule/package-comments.go | 10 +--------- testdata/golint/package-doc4.go | 7 ------- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 testdata/golint/package-doc4.go diff --git a/rule/package-comments.go b/rule/package-comments.go index 02f246be0..403df21a6 100644 --- a/rule/package-comments.go +++ b/rule/package-comments.go @@ -150,15 +150,7 @@ 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) { l.onFailure(lint.Failure{ 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 From 753687c6839f610cffd7deca2fa3531500b3c527 Mon Sep 17 00:00:00 2001 From: chavacava Date: Sat, 11 May 2024 20:22:50 +0200 Subject: [PATCH 2/2] skips directive comments when linting package comments --- rule/package-comments.go | 2 +- testdata/golint/package-doc6.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 testdata/golint/package-doc6.go diff --git a/rule/package-comments.go b/rule/package-comments.go index 403df21a6..f1e5462fe 100644 --- a/rule/package-comments.go +++ b/rule/package-comments.go @@ -152,7 +152,7 @@ func (l *lintPackageComments) Visit(_ ast.Node) ast.Visitor { s := l.fileAst.Doc.Text() // 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-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/