@@ -18,13 +18,15 @@ func TestExclusionPaths_Process(t *testing.T) {
18
18
19
19
testCases := []struct {
20
20
desc string
21
- patterns [] string
21
+ cfg * config. LinterExclusions
22
22
issues []result.Issue
23
23
expected []result.Issue
24
24
}{
25
25
{
26
- desc : "word" ,
27
- patterns : []string {"foo" },
26
+ desc : "paths: word" ,
27
+ cfg : & config.LinterExclusions {
28
+ Paths : []string {"foo" },
29
+ },
28
30
issues : []result.Issue {
29
31
{RelativePath : "foo.go" },
30
32
{RelativePath : "foo/foo.go" },
@@ -37,8 +39,10 @@ func TestExclusionPaths_Process(t *testing.T) {
37
39
},
38
40
},
39
41
{
40
- desc : "begin with word" ,
41
- patterns : []string {"^foo" },
42
+ desc : "paths: begin with word" ,
43
+ cfg : & config.LinterExclusions {
44
+ Paths : []string {"^foo" },
45
+ },
42
46
issues : []result.Issue {
43
47
{RelativePath : filepath .FromSlash ("foo.go" )},
44
48
{RelativePath : filepath .FromSlash ("foo/foo.go" )},
@@ -52,8 +56,10 @@ func TestExclusionPaths_Process(t *testing.T) {
52
56
},
53
57
},
54
58
{
55
- desc : "directory begin with word" ,
56
- patterns : []string {"^foo/" },
59
+ desc : "paths: directory begin with word" ,
60
+ cfg : & config.LinterExclusions {
61
+ Paths : []string {"^foo/" },
62
+ },
57
63
issues : []result.Issue {
58
64
{RelativePath : filepath .FromSlash ("foo.go" )},
59
65
{RelativePath : filepath .FromSlash ("foo/foo.go" )},
@@ -68,17 +74,21 @@ func TestExclusionPaths_Process(t *testing.T) {
68
74
},
69
75
},
70
76
{
71
- desc : "same suffix with unconstrained expression" ,
72
- patterns : []string {"c/d.go" },
77
+ desc : "paths: same suffix with unconstrained expression" ,
78
+ cfg : & config.LinterExclusions {
79
+ Paths : []string {"c/d.go" },
80
+ },
73
81
issues : []result.Issue {
74
82
{RelativePath : filepath .FromSlash ("a/b/c/d.go" )},
75
83
{RelativePath : filepath .FromSlash ("c/d.go" )},
76
84
},
77
85
expected : []result.Issue {},
78
86
},
79
87
{
80
- desc : "same suffix with constrained expression" ,
81
- patterns : []string {"^c/d.go" },
88
+ desc : "paths: same suffix with constrained expression" ,
89
+ cfg : & config.LinterExclusions {
90
+ Paths : []string {"^c/d.go" },
91
+ },
82
92
issues : []result.Issue {
83
93
{RelativePath : filepath .FromSlash ("a/b/c/d.go" )},
84
94
{RelativePath : filepath .FromSlash ("c/d.go" )},
@@ -87,13 +97,51 @@ func TestExclusionPaths_Process(t *testing.T) {
87
97
{RelativePath : filepath .FromSlash ("a/b/c/d.go" )},
88
98
},
89
99
},
100
+ {
101
+ desc : "pathsExcept" ,
102
+ cfg : & config.LinterExclusions {
103
+ PathsExcept : []string {`^base/c/.*$` },
104
+ },
105
+ issues : []result.Issue {
106
+ {RelativePath : filepath .FromSlash ("base/a/file.go" )},
107
+ {RelativePath : filepath .FromSlash ("base/b/file.go" )},
108
+ {RelativePath : filepath .FromSlash ("base/c/file.go" )},
109
+ {RelativePath : filepath .FromSlash ("base/c/a/file.go" )},
110
+ {RelativePath : filepath .FromSlash ("base/c/b/file.go" )},
111
+ {RelativePath : filepath .FromSlash ("base/d/file.go" )},
112
+ },
113
+ expected : []result.Issue {
114
+ {RelativePath : filepath .FromSlash ("base/a/file.go" )},
115
+ {RelativePath : filepath .FromSlash ("base/b/file.go" )},
116
+ {RelativePath : filepath .FromSlash ("base/d/file.go" )},
117
+ },
118
+ },
119
+ {
120
+ desc : "pathsExcept and paths" ,
121
+ cfg : & config.LinterExclusions {
122
+ Paths : []string {"^base/b/" },
123
+ PathsExcept : []string {`^base/c/.*$` },
124
+ },
125
+ issues : []result.Issue {
126
+ {RelativePath : filepath .FromSlash ("base/a/file.go" )},
127
+ {RelativePath : filepath .FromSlash ("base/b/file.go" )},
128
+ {RelativePath : filepath .FromSlash ("base/c/file.go" )},
129
+ {RelativePath : filepath .FromSlash ("base/c/a/file.go" )},
130
+ {RelativePath : filepath .FromSlash ("base/c/b/file.go" )},
131
+ {RelativePath : filepath .FromSlash ("base/d/file.go" )},
132
+ },
133
+ expected : []result.Issue {
134
+ {RelativePath : filepath .FromSlash ("base/a/file.go" )},
135
+ {RelativePath : filepath .FromSlash ("base/d/file.go" )},
136
+ },
137
+ },
90
138
}
91
139
92
140
for _ , test := range testCases {
93
141
t .Run (test .desc , func (t * testing.T ) {
94
142
t .Parallel ()
95
143
96
- p , err := NewExclusionPaths (logger , & config. LinterExclusions { Paths : test .patterns } )
144
+ p , err := NewExclusionPaths (logger , test .cfg )
97
145
require .NoError (t , err )
98
146
99
147
processedIssues := process (t , p , test .issues ... )
0 commit comments