From 5080c30c845942f9ca34faec877d8179ee70f2e9 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 3 Aug 2023 09:54:15 +0200 Subject: [PATCH] lll: ignore comments containing only URL --- pkg/golinters/lll.go | 7 +++++++ test/testdata/lll_comment_url.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/testdata/lll_comment_url.go diff --git a/pkg/golinters/lll.go b/pkg/golinters/lll.go index 9ed320120960..b0b52e31852c 100644 --- a/pkg/golinters/lll.go +++ b/pkg/golinters/lll.go @@ -5,6 +5,7 @@ import ( "fmt" "go/token" "os" + "regexp" "strings" "sync" "unicode/utf8" @@ -89,6 +90,8 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r lineNumber := 0 multiImportEnabled := false + urlComment := regexp.MustCompile(`\s*//\s*http(s)?://[^ ]+$`) + scanner := bufio.NewScanner(f) for scanner.Scan() { lineNumber++ @@ -100,6 +103,10 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r continue } + if urlComment.MatchString(line) { + continue + } + if strings.HasPrefix(line, "import") { multiImportEnabled = strings.HasSuffix(line, "(") continue diff --git a/test/testdata/lll_comment_url.go b/test/testdata/lll_comment_url.go new file mode 100644 index 000000000000..83d8d1c7f9f1 --- /dev/null +++ b/test/testdata/lll_comment_url.go @@ -0,0 +1,20 @@ +//golangcitest:args -Elll +//golangcitest:config_path testdata/configs/lll.yml +package testdata + +import ( + "fmt" + _ "unsafe" +) + +// https://github.com/golangci/golangci-lint/blob/master/pkg/result/processors/testdata/autogen_exclude_block_comment.go +func lllCommentURL1() { + // https://github.com/golangci/golangci-lint/blob/master/pkg/result/processors/testdata/autogen_exclude_block_comment.go + fmt.Println("lll") +} + +// https://github.com/golangci/golangci-lint/blob/master/pkg/result/processors/testdata/autogen_exclude_block_comment.go foobar // want "line is 160 characters" +func lllCommentURL2() { + // https://github.com/golangci/golangci-lint/blob/master/pkg/result/processors/testdata/autogen_exclude_block_comment.go foobar // want "line is 164 characters" + fmt.Println("lll") +}