Skip to content

Commit

Permalink
chore: remove ExcludeOptions and getExcludeProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Apr 24, 2024
1 parent c39f59d commit d3c95a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
14 changes: 1 addition & 13 deletions pkg/lint/runner.go
Expand Up @@ -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),

Expand Down Expand Up @@ -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)
}
21 changes: 12 additions & 9 deletions 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"
)

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkg/result/processors/exclude_test.go
Expand Up @@ -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"}

Expand All @@ -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"}

Expand Down

0 comments on commit d3c95a2

Please sign in to comment.