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

lll: ignore comments containing only URL #3986

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions pkg/golinters/lll.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"go/token"
"os"
"regexp"
"strings"
"sync"
"unicode/utf8"
Expand Down Expand Up @@ -89,6 +90,8 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
lineNumber := 0
multiImportEnabled := false

urlComment := regexp.MustCompile(`\s*//\s*http(s)?://[^ ]+$`)
Copy link
Contributor

@mattdowdell mattdowdell Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to also exclude URLs used as reference links? e.g.

Here's a [link] and [another][1]!

[link]: https://example.com
[1]: https://example.com

I sometimes use these references to keep Go docs readable when browsing code (inserting long URLs makes following text hard), and given modern godoc uses markdown, this would likely be universally helpful.


scanner := bufio.NewScanner(f)
for scanner.Scan() {
lineNumber++
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/testdata/lll_comment_url.go
Original file line number Diff line number Diff line change
@@ -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
ldez marked this conversation as resolved.
Show resolved Hide resolved
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")
}