From d3c95a2b221e2ea74ea8b19cea783ff73ebfd065 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 24 Apr 2024 15:33:13 +0200 Subject: [PATCH] chore: remove ExcludeOptions and getExcludeProcessor --- pkg/lint/runner.go | 14 +------------- pkg/result/processors/exclude.go | 21 ++++++++++++--------- pkg/result/processors/exclude_test.go | 7 ++++--- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index 13ee2ba1897a..f4877e1e89c6 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -80,7 +80,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti // Must be before exclude because users see already marked output and configure excluding by it. processors.NewIdentifierMarker(), - getExcludeProcessor(&cfg.Issues), + processors.NewExclude(&cfg.Issues), processors.NewExcludeRules(log.Child(logutils.DebugKeyExcludeRules), files, &cfg.Issues), processors.NewNolint(log.Child(logutils.DebugKeyNolint), dbManager, enabledLinters), @@ -242,15 +242,3 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s return issues } - -func getExcludeProcessor(cfg *config.Issues) processors.Processor { - opts := processors.ExcludeOptions{ - CaseSensitive: cfg.ExcludeCaseSensitive, - } - - if len(cfg.ExcludePatterns) != 0 { - opts.Pattern = fmt.Sprintf("(%s)", strings.Join(cfg.ExcludePatterns, "|")) - } - - return processors.NewExclude(opts) -} diff --git a/pkg/result/processors/exclude.go b/pkg/result/processors/exclude.go index 15ad7f7dee0c..5431204502a7 100644 --- a/pkg/result/processors/exclude.go +++ b/pkg/result/processors/exclude.go @@ -1,8 +1,11 @@ package processors import ( + "fmt" "regexp" + "strings" + "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/result" ) @@ -14,22 +17,22 @@ type Exclude struct { pattern *regexp.Regexp } -type ExcludeOptions struct { - Pattern string - CaseSensitive bool -} - -func NewExclude(opts ExcludeOptions) *Exclude { +func NewExclude(cfg *config.Issues) *Exclude { p := &Exclude{name: "exclude"} + var pattern string + if len(cfg.ExcludePatterns) != 0 { + pattern = fmt.Sprintf("(%s)", strings.Join(cfg.ExcludePatterns, "|")) + } + prefix := caseInsensitivePrefix - if opts.CaseSensitive { + if cfg.ExcludeCaseSensitive { p.name = "exclude-case-sensitive" prefix = "" } - if opts.Pattern != "" { - p.pattern = regexp.MustCompile(prefix + opts.Pattern) + if pattern != "" { + p.pattern = regexp.MustCompile(prefix + pattern) } return p diff --git a/pkg/result/processors/exclude_test.go b/pkg/result/processors/exclude_test.go index a62f4ef5c362..f81eb49c7646 100644 --- a/pkg/result/processors/exclude_test.go +++ b/pkg/result/processors/exclude_test.go @@ -5,11 +5,12 @@ import ( "github.com/stretchr/testify/assert" + "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/result" ) func TestExclude(t *testing.T) { - p := NewExclude(ExcludeOptions{Pattern: "^exclude$"}) + p := NewExclude(&config.Issues{ExcludePatterns: []string{"^exclude$"}}) texts := []string{"excLude", "1", "", "exclud", "notexclude"} @@ -30,11 +31,11 @@ func TestExclude(t *testing.T) { } func TestExclude_empty(t *testing.T) { - processAssertSame(t, NewExclude(ExcludeOptions{}), newIssueFromTextTestCase("test")) + processAssertSame(t, NewExclude(&config.Issues{}), newIssueFromTextTestCase("test")) } func TestExclude_caseSensitive(t *testing.T) { - p := NewExclude(ExcludeOptions{Pattern: "^exclude$", CaseSensitive: true}) + p := NewExclude(&config.Issues{ExcludePatterns: []string{"^exclude$"}, ExcludeCaseSensitive: true}) texts := []string{"excLude", "1", "", "exclud", "exclude"}