github.com/ldez/golangci-lint@v1.10.1/pkg/result/processors/exclude.go (about)

     1  package processors
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"github.com/golangci/golangci-lint/pkg/result"
     7  )
     8  
     9  type Exclude struct {
    10  	pattern *regexp.Regexp
    11  }
    12  
    13  var _ Processor = Exclude{}
    14  
    15  func NewExclude(pattern string) *Exclude {
    16  	var patternRe *regexp.Regexp
    17  	if pattern != "" {
    18  		patternRe = regexp.MustCompile("(?i)" + pattern)
    19  	}
    20  	return &Exclude{
    21  		pattern: patternRe,
    22  	}
    23  }
    24  
    25  func (p Exclude) Name() string {
    26  	return "exclude"
    27  }
    28  
    29  func (p Exclude) Process(issues []result.Issue) ([]result.Issue, error) {
    30  	if p.pattern == nil {
    31  		return issues, nil
    32  	}
    33  
    34  	return filterIssues(issues, func(i *result.Issue) bool {
    35  		return !p.pattern.MatchString(i.Text)
    36  	}), nil
    37  }
    38  
    39  func (p Exclude) Finish() {}