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

Conversation

ldez
Copy link
Member

@ldez ldez commented Aug 3, 2023

As illustrated in the following example, to ignore long URLs the nolint directive should be placed on the top of the comments but this ignores lll on the whole function.

.golangci.yml
linters:
  disable-all: true
  enable:
    - lll
    - typecheck

linters-settings:
  lll:
    line-length: 50
package main

import "fmt"

// main runs the app.
// https://github.com/walle/lll/blob/4438bccd245f7e87a5a69023625f01e7035c05c0/utils.go#L15
//
//nolint:lll
func main() {
	fmt.Println("Foo")
}
$ golangci-lint run 
$

Fixes #3983

@ldez ldez added enhancement New feature or improvement linter: update Update the linter implementation inside golangci-lint labels Aug 3, 2023
@ldez ldez added the blocked Need's direct action from maintainer label Oct 9, 2023
@@ -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.

@batazor
Copy link

batazor commented Nov 29, 2023

Sometimes in the code you have to leave links to tasks in the tracker or links to discussion of some bugs - to understand why it was done this way.

And often they are long links, it would be cool to be able to skip such cases by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Need's direct action from maintainer enhancement New feature or improvement linter: update Update the linter implementation inside golangci-lint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lll: Ignore long URLs, strings, and struct tags
4 participants