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: skip imports #3288

Merged
merged 5 commits into from Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/golinters/lll.go
Expand Up @@ -85,10 +85,28 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
defer f.Close()

lineNumber := 1
multiImportEnabled := false

scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
line = strings.ReplaceAll(line, "\t", tabSpaces)

if strings.HasPrefix(line, "import") {
multiImportEnabled = strings.HasSuffix(line, "(")
lineNumber++
continue
}

if multiImportEnabled {
if line == ")" {
multiImportEnabled = false
}

lineNumber++
continue
}

lineLen := utf8.RuneCountInString(line)
if lineLen > maxLineLen {
res = append(res, result.Issue{
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/configs/lll_import.yml
@@ -0,0 +1,4 @@
linters-settings:
lll:
tab-width: 4
line-length: 60
14 changes: 14 additions & 0 deletions test/testdata/lll_multi_import.go
@@ -0,0 +1,14 @@
//golangcitest:args -Elll
//golangcitest:config_path testdata/configs/lll_import.yml
//golangcitest:expected_exitcode 0
package testdata

import (
anotherVeryLongImportAliasNameForTest "github.com/golangci/golangci-lint/internal/golinters"
veryLongImportAliasNameForTest "github.com/golangci/golangci-lint/internal/golinters"
)

func LllMultiImport() {
_ = veryLongImportAliasNameForTest.NewLLL(nil)
_ = anotherVeryLongImportAliasNameForTest.NewLLL(nil)
}
10 changes: 10 additions & 0 deletions test/testdata/lll_single_import.go
@@ -0,0 +1,10 @@
//golangcitest:args -Elll
//golangcitest:config_path testdata/configs/lll_import.yml
//golangcitest:expected_exitcode 0
package testdata

import veryLongImportAliasNameForTest "github.com/golangci/golangci-lint/internal/golinters"

func LllSingleImport() {
_ = veryLongImportAliasNameForTest.NewLLL(nil)
}