golangci-lint/pkg/result/processors/exclude.go

60 lines
1.1 KiB
Go
Raw Normal View History

2018-05-07 21:44:40 +03:00
package processors
import (
"regexp"
"github.com/golangci/golangci-lint/pkg/result"
)
type Exclude struct {
pattern *regexp.Regexp
}
var _ Processor = Exclude{}
func NewExclude(pattern string) *Exclude {
var patternRe *regexp.Regexp
if pattern != "" {
2018-05-08 22:28:29 +03:00
patternRe = regexp.MustCompile("(?i)" + pattern)
2018-05-07 21:44:40 +03:00
}
return &Exclude{
pattern: patternRe,
}
}
func (p Exclude) Name() string {
return "exclude"
}
func (p Exclude) Process(issues []result.Issue) ([]result.Issue, error) {
if p.pattern == nil {
return issues, nil
}
return filterIssues(issues, func(i *result.Issue) bool {
return !p.pattern.MatchString(i.Text)
}), nil
}
func (p Exclude) Finish() {}
type ExcludeCaseSensitive struct {
*Exclude
}
var _ Processor = ExcludeCaseSensitive{}
func NewExcludeCaseSensitive(pattern string) *ExcludeCaseSensitive {
var patternRe *regexp.Regexp
if pattern != "" {
patternRe = regexp.MustCompile(pattern)
}
return &ExcludeCaseSensitive{
&Exclude{pattern: patternRe},
}
}
func (p ExcludeCaseSensitive) Name() string {
return "exclude-case-sensitive"
}