Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6bece11

Browse files
Ivan Bezrodnovibez92
Ivan Bezrodnov
authored andcommittedOct 10, 2022
lll skip imports
1 parent d03294f commit 6bece11

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

Diff for: ‎pkg/golinters/lll.go

+28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"go/token"
77
"os"
8+
"regexp"
89
"strings"
910
"sync"
1011
"unicode/utf8"
@@ -19,6 +20,9 @@ import (
1920

2021
const lllName = "lll"
2122

23+
var lllMultiImportStartRegexp = regexp.MustCompile(`^import \($`)
24+
var lllSingleImportRegexp = regexp.MustCompile(`^import \".+\"$`)
25+
2226
//nolint:dupl
2327
func NewLLL(settings *config.LllSettings) *goanalysis.Linter {
2428
var mu sync.Mutex
@@ -86,9 +90,33 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
8690

8791
lineNumber := 1
8892
scanner := bufio.NewScanner(f)
93+
importsEnded := false
94+
multiImportEnabled := false
8995
for scanner.Scan() {
9096
line := scanner.Text()
9197
line = strings.ReplaceAll(line, "\t", tabSpaces)
98+
// Skips imports
99+
if !importsEnded {
100+
if lllSingleImportRegexp.MatchString(line) {
101+
lineNumber++
102+
continue
103+
}
104+
105+
if lllMultiImportStartRegexp.MatchString(line) {
106+
multiImportEnabled = true
107+
lineNumber++
108+
continue
109+
}
110+
111+
if multiImportEnabled && line == ")" {
112+
importsEnded = true
113+
lineNumber++
114+
continue
115+
}
116+
117+
importsEnded = true
118+
}
119+
92120
lineLen := utf8.RuneCountInString(line)
93121
if lineLen > maxLineLen {
94122
res = append(res, result.Issue{

0 commit comments

Comments
 (0)
Please sign in to comment.