Skip to content

Commit

Permalink
lll skip imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Bezrodnov authored and ibez92 committed Oct 10, 2022
1 parent d03294f commit 6bece11
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/golinters/lll.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"go/token"
"os"
"regexp"
"strings"
"sync"
"unicode/utf8"
Expand All @@ -19,6 +20,9 @@ import (

const lllName = "lll"

var lllMultiImportStartRegexp = regexp.MustCompile(`^import \($`)
var lllSingleImportRegexp = regexp.MustCompile(`^import \".+\"$`)

//nolint:dupl
func NewLLL(settings *config.LllSettings) *goanalysis.Linter {
var mu sync.Mutex
Expand Down Expand Up @@ -86,9 +90,33 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r

lineNumber := 1
scanner := bufio.NewScanner(f)
importsEnded := false
multiImportEnabled := false
for scanner.Scan() {
line := scanner.Text()
line = strings.ReplaceAll(line, "\t", tabSpaces)
// Skips imports
if !importsEnded {
if lllSingleImportRegexp.MatchString(line) {
lineNumber++
continue
}

if lllMultiImportStartRegexp.MatchString(line) {
multiImportEnabled = true
lineNumber++
continue
}

if multiImportEnabled && line == ")" {
importsEnded = true
lineNumber++
continue
}

importsEnded = true
}

lineLen := utf8.RuneCountInString(line)
if lineLen > maxLineLen {
res = append(res, result.Issue{
Expand Down

0 comments on commit 6bece11

Please sign in to comment.