Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

lll: ignore comments containing only URL#3986

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ldez wants to merge1 commit intogolangci:master
base:master
Choose a base branch
Loading
fromldez:feat/lll-url-comments
Open
Show file tree
Hide file tree
Changes fromall 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
lll: ignore comments containing only URL
  • Loading branch information
@ldez
ldez committedAug 3, 2023
commit5080c30c845942f9ca34faec877d8179ee70f2e9
7 changes: 7 additions & 0 deletionspkg/golinters/lll.go
View file
Open in desktop
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
edited
Loading

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.

alexandear reacted with thumbs up emoji

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+"

ccoVeille and theory reacted with thumbs up emoji

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 deletionstest/testdata/lll_comment_url.go
View file
Open in desktop
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")
}

[8]ページ先頭

©2009-2025 Movatter.jp