diff --git a/pkg/golinters/lll.go b/pkg/golinters/lll.go index 8b5ebd3cf57f..551ff98a2c87 100644 --- a/pkg/golinters/lll.go +++ b/pkg/golinters/lll.go @@ -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{ @@ -100,7 +118,6 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r FromLinter: lllName, }) } - lineNumber++ } if err := scanner.Err(); err != nil { diff --git a/test/testdata/configs/lll_import.yml b/test/testdata/configs/lll_import.yml new file mode 100644 index 000000000000..e281e3d24513 --- /dev/null +++ b/test/testdata/configs/lll_import.yml @@ -0,0 +1,4 @@ +linters-settings: + lll: + tab-width: 4 + line-length: 60 diff --git a/test/testdata/lll_multi_import.go b/test/testdata/lll_multi_import.go new file mode 100644 index 000000000000..4c2ab5ab477e --- /dev/null +++ b/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) +} diff --git a/test/testdata/lll_single_import.go b/test/testdata/lll_single_import.go new file mode 100644 index 000000000000..ed86985aa568 --- /dev/null +++ b/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) +}