lll: skip imports (#3288)
This commit is contained in:
parent
2823ec6215
commit
8a1cf904f9
@ -84,11 +84,29 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
lineNumber := 1
|
lineNumber := 0
|
||||||
|
multiImportEnabled := false
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
lineNumber++
|
||||||
|
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
line = strings.ReplaceAll(line, "\t", tabSpaces)
|
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)
|
lineLen := utf8.RuneCountInString(line)
|
||||||
if lineLen > maxLineLen {
|
if lineLen > maxLineLen {
|
||||||
res = append(res, result.Issue{
|
res = append(res, result.Issue{
|
||||||
@ -100,7 +118,6 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
|
|||||||
FromLinter: lllName,
|
FromLinter: lllName,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
lineNumber++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
|
4
test/testdata/configs/lll_import.yml
vendored
Normal file
4
test/testdata/configs/lll_import.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
linters-settings:
|
||||||
|
lll:
|
||||||
|
tab-width: 4
|
||||||
|
line-length: 60
|
14
test/testdata/lll_multi_import.go
vendored
Normal file
14
test/testdata/lll_multi_import.go
vendored
Normal file
@ -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
test/testdata/lll_single_import.go
vendored
Normal file
10
test/testdata/lll_single_import.go
vendored
Normal file
@ -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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user