/
exclude.go
59 lines (46 loc) · 1.06 KB
/
exclude.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package processors
import (
"regexp"
"github.com/hitzhangjie/go-readability/pkg/result"
)
type Exclude struct {
pattern *regexp.Regexp
}
var _ Processor = Exclude{}
func NewExclude(pattern string) *Exclude {
var patternRe *regexp.Regexp
if pattern != "" {
patternRe = regexp.MustCompile("(?i)" + pattern)
}
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"
}