Skip to content

Commit 8a1cf90

Browse files
authored
lll: skip imports (#3288)
1 parent 2823ec6 commit 8a1cf90

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

Diff for: pkg/golinters/lll.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,29 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
8484
}
8585
defer f.Close()
8686

87-
lineNumber := 1
87+
lineNumber := 0
88+
multiImportEnabled := false
89+
8890
scanner := bufio.NewScanner(f)
8991
for scanner.Scan() {
92+
lineNumber++
93+
9094
line := scanner.Text()
9195
line = strings.ReplaceAll(line, "\t", tabSpaces)
96+
97+
if strings.HasPrefix(line, "import") {
98+
multiImportEnabled = strings.HasSuffix(line, "(")
99+
continue
100+
}
101+
102+
if multiImportEnabled {
103+
if line == ")" {
104+
multiImportEnabled = false
105+
}
106+
107+
continue
108+
}
109+
92110
lineLen := utf8.RuneCountInString(line)
93111
if lineLen > maxLineLen {
94112
res = append(res, result.Issue{
@@ -100,7 +118,6 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
100118
FromLinter: lllName,
101119
})
102120
}
103-
lineNumber++
104121
}
105122

106123
if err := scanner.Err(); err != nil {

Diff for: test/testdata/configs/lll_import.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
lll:
3+
tab-width: 4
4+
line-length: 60

Diff for: test/testdata/lll_multi_import.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//golangcitest:args -Elll
2+
//golangcitest:config_path testdata/configs/lll_import.yml
3+
//golangcitest:expected_exitcode 0
4+
package testdata
5+
6+
import (
7+
anotherVeryLongImportAliasNameForTest "github.com/golangci/golangci-lint/internal/golinters"
8+
veryLongImportAliasNameForTest "github.com/golangci/golangci-lint/internal/golinters"
9+
)
10+
11+
func LllMultiImport() {
12+
_ = veryLongImportAliasNameForTest.NewLLL(nil)
13+
_ = anotherVeryLongImportAliasNameForTest.NewLLL(nil)
14+
}

Diff for: test/testdata/lll_single_import.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//golangcitest:args -Elll
2+
//golangcitest:config_path testdata/configs/lll_import.yml
3+
//golangcitest:expected_exitcode 0
4+
package testdata
5+
6+
import veryLongImportAliasNameForTest "github.com/golangci/golangci-lint/internal/golinters"
7+
8+
func LllSingleImport() {
9+
_ = veryLongImportAliasNameForTest.NewLLL(nil)
10+
}

0 commit comments

Comments
 (0)