github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/result/processors/exclude.go (about)

     1  package processors
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"github.com/elek/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() {}
    40  
    41  type ExcludeCaseSensitive struct {
    42  	*Exclude
    43  }
    44  
    45  var _ Processor = ExcludeCaseSensitive{}
    46  
    47  func NewExcludeCaseSensitive(pattern string) *ExcludeCaseSensitive {
    48  	var patternRe *regexp.Regexp
    49  	if pattern != "" {
    50  		patternRe = regexp.MustCompile(pattern)
    51  	}
    52  	return &ExcludeCaseSensitive{
    53  		&Exclude{pattern: patternRe},
    54  	}
    55  }
    56  
    57  func (p ExcludeCaseSensitive) Name() string {
    58  	return "exclude-case-sensitive"
    59  }