Skip to content
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 numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import (
"fmt"
"go/token"
"os"
"regexp"
"strings"
"sync"
"unicode/utf8"
Expand DownExpand 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

@mattdowdellmattdowdellOct 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.

Choose a reason for hiding this comment

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

For that I specifically use:

exclude-rules: - linters: - lllsource: "^// \\[.*\\]: \\w+"


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 numberDiff line numberDiff 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
funclllCommentURL1(){
// 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"
funclllCommentURL2(){
// 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")
}