Skip to content
Merged
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
21 changes: 19 additions & 2 deletions pkg/golinters/lll.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,29 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
}
defer f.Close()

lineNumber := 1
lineNumber := 0
multiImportEnabled := false

scanner := bufio.NewScanner(f)
for scanner.Scan() {
lineNumber++

line := scanner.Text()
line = strings.ReplaceAll(line, "\t", tabSpaces)

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

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

continue
}

lineLen := utf8.RuneCountInString(line)
if lineLen > maxLineLen {
res = append(res, result.Issue{
Expand All @@ -100,7 +118,6 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
FromLinter: lllName,
})
}
lineNumber++
}

if err := scanner.Err(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/configs/lll_import.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
}