forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathskip_files.go
62 lines (48 loc) · 1.25 KB
/
skip_files.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
60
61
62
package processors
import (
"fmt"
"regexp"
"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*SkipFiles)(nil)
// SkipFiles filters reports based on filename.
//
// It uses the shortest relative paths and `path-prefix` option.
type SkipFiles struct {
patterns []*regexp.Regexp
pathPrefix string
}
func NewSkipFiles(patterns []string, pathPrefix string) (*SkipFiles, error) {
var patternsRe []*regexp.Regexp
for _, p := range patterns {
p = fsutils.NormalizePathInRegex(p)
patternRe, err := regexp.Compile(p)
if err != nil {
return nil, fmt.Errorf("can't compile regexp %q: %w", p, err)
}
patternsRe = append(patternsRe, patternRe)
}
return &SkipFiles{
patterns: patternsRe,
pathPrefix: pathPrefix,
}, nil
}
func (SkipFiles) Name() string {
return "skip_files"
}
func (p SkipFiles) Process(issues []result.Issue) ([]result.Issue, error) {
if len(p.patterns) == 0 {
return issues, nil
}
return filterIssues(issues, func(issue *result.Issue) bool {
path := fsutils.WithPathPrefix(p.pathPrefix, issue.FilePath())
for _, pattern := range p.patterns {
if pattern.MatchString(path) {
return false
}
}
return true
}), nil
}
func (SkipFiles) Finish() {}