From 9ad980b183e14961c75ba135a6d7992e2698d6a2 Mon Sep 17 00:00:00 2001 From: Ivan Bezrodnov Date: Mon, 10 Oct 2022 09:55:27 +0600 Subject: [PATCH] remove regexps and fix multiImport condition --- pkg/golinters/lll.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/golinters/lll.go b/pkg/golinters/lll.go index 55979cdfd62f..de2c56825fa8 100644 --- a/pkg/golinters/lll.go +++ b/pkg/golinters/lll.go @@ -5,7 +5,6 @@ import ( "fmt" "go/token" "os" - "regexp" "strings" "sync" "unicode/utf8" @@ -20,9 +19,6 @@ 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 @@ -97,19 +93,16 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r line = strings.ReplaceAll(line, "\t", tabSpaces) // Skips imports if !importsEnded { - if lllSingleImportRegexp.MatchString(line) { - lineNumber++ - continue - } + if strings.HasPrefix(line, "import") { + if strings.HasSuffix(line, "(") { + multiImportEnabled = true + } - if lllMultiImportStartRegexp.MatchString(line) { - multiImportEnabled = true lineNumber++ continue } - if multiImportEnabled && line == ")" { - importsEnded = true + if multiImportEnabled && line != ")" { lineNumber++ continue }