2018-05-07 21:44:40 +03:00
|
|
|
package processors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
|
|
)
|
|
|
|
|
2024-03-29 21:00:18 +01:00
|
|
|
var _ Processor = (*Exclude)(nil)
|
2024-03-05 14:39:49 +01:00
|
|
|
|
2018-05-07 21:44:40 +03:00
|
|
|
type Exclude struct {
|
2024-03-05 14:39:49 +01:00
|
|
|
name string
|
|
|
|
|
2018-05-07 21:44:40 +03:00
|
|
|
pattern *regexp.Regexp
|
|
|
|
}
|
|
|
|
|
2024-03-05 14:39:49 +01:00
|
|
|
type ExcludeOptions struct {
|
|
|
|
Pattern string
|
|
|
|
CaseSensitive bool
|
|
|
|
}
|
2018-05-07 21:44:40 +03:00
|
|
|
|
2024-03-05 14:39:49 +01:00
|
|
|
func NewExclude(opts ExcludeOptions) *Exclude {
|
|
|
|
p := &Exclude{name: "exclude"}
|
|
|
|
|
|
|
|
prefix := caseInsensitivePrefix
|
|
|
|
if opts.CaseSensitive {
|
|
|
|
p.name = "exclude-case-sensitive"
|
|
|
|
prefix = ""
|
2018-05-07 21:44:40 +03:00
|
|
|
}
|
2024-03-05 14:39:49 +01:00
|
|
|
|
|
|
|
if opts.Pattern != "" {
|
|
|
|
p.pattern = regexp.MustCompile(prefix + opts.Pattern)
|
2018-05-07 21:44:40 +03:00
|
|
|
}
|
2024-03-05 14:39:49 +01:00
|
|
|
|
|
|
|
return p
|
2018-05-07 21:44:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p Exclude) Name() string {
|
2024-03-05 14:39:49 +01:00
|
|
|
return p.name
|
2018-05-07 21:44:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p Exclude) Process(issues []result.Issue) ([]result.Issue, error) {
|
|
|
|
if p.pattern == nil {
|
|
|
|
return issues, nil
|
|
|
|
}
|
|
|
|
|
2024-03-05 19:02:58 +02:00
|
|
|
return filterIssues(issues, func(issue *result.Issue) bool {
|
|
|
|
return !p.pattern.MatchString(issue.Text)
|
2018-05-07 21:44:40 +03:00
|
|
|
}), nil
|
|
|
|
}
|
2018-05-08 08:15:55 +03:00
|
|
|
|
2024-03-29 21:00:18 +01:00
|
|
|
func (Exclude) Finish() {}
|