@@ -14,36 +14,6 @@ import (
14
14
15
15
var _ Processor = (* ExclusionRules )(nil )
16
16
17
- type excludeRule struct {
18
- baseRule
19
- }
20
-
21
- func (e excludeRule ) String () string {
22
- var msg []string
23
-
24
- if e .text != nil && e .text .String () != "" {
25
- msg = append (msg , fmt .Sprintf ("Text: %q" , e .text ))
26
- }
27
-
28
- if e .source != nil && e .source .String () != "" {
29
- msg = append (msg , fmt .Sprintf ("Source: %q" , e .source ))
30
- }
31
-
32
- if e .path != nil && e .path .String () != "" {
33
- msg = append (msg , fmt .Sprintf ("Path: %q" , e .path ))
34
- }
35
-
36
- if e .pathExcept != nil && e .pathExcept .String () != "" {
37
- msg = append (msg , fmt .Sprintf ("Path Except: %q" , e .pathExcept ))
38
- }
39
-
40
- if len (e .linters ) > 0 {
41
- msg = append (msg , fmt .Sprintf ("Linters: %q" , strings .Join (e .linters , ", " )))
42
- }
43
-
44
- return strings .Join (msg , ", " )
45
- }
46
-
47
17
type ExclusionRules struct {
48
18
log logutils.Log
49
19
files * fsutils.Files
@@ -68,18 +38,18 @@ func NewExclusionRules(log logutils.Log, files *fsutils.Files, cfg *config.Linte
68
38
prefix = ""
69
39
}
70
40
71
- excludeRules := slices .Clone (cfg .Rules )
72
- excludeRules = append ( excludeRules , filterInclude (getDefaultLintersExclusions (cfg .Default ), oldCfg .IncludeDefaultExcludes )... )
41
+ excludeRules := slices .Concat ( slices . Clone (cfg .Rules ),
42
+ filterInclude (getDefaultLintersExclusions (cfg .Default ), oldCfg .IncludeDefaultExcludes ))
73
43
74
- p .rules = createRules (excludeRules , prefix )
44
+ p .rules = createExcludeRules (excludeRules , prefix )
75
45
76
46
// TODO(ldez): should be removed in v2.
77
47
for _ , pattern := range oldCfg .ExcludePatterns {
78
48
if pattern == "" {
79
49
continue
80
50
}
81
51
82
- rule := createRule (& config.ExcludeRule {
52
+ rule := newRule (& config.ExcludeRule {
83
53
BaseRule : config.BaseRule {
84
54
Path : `.+\.go` ,
85
55
Text : pattern ,
@@ -135,21 +105,11 @@ func (p *ExclusionRules) Finish() {
135
105
}
136
106
}
137
107
138
- func createRules (rules []config.ExcludeRule , prefix string ) []excludeRule {
139
- if len (rules ) == 0 {
140
- return nil
141
- }
142
-
143
- parsedRules := make ([]excludeRule , 0 , len (rules ))
144
-
145
- for _ , rule := range rules {
146
- parsedRules = append (parsedRules , createRule (& rule , prefix ))
147
- }
148
-
149
- return parsedRules
108
+ type excludeRule struct {
109
+ baseRule
150
110
}
151
111
152
- func createRule (rule * config.ExcludeRule , prefix string ) excludeRule {
112
+ func newRule (rule * config.ExcludeRule , prefix string ) excludeRule {
153
113
parsedRule := excludeRule {}
154
114
parsedRule .linters = rule .Linters
155
115
parsedRule .internalReference = rule .InternalReference
@@ -173,6 +133,46 @@ func createRule(rule *config.ExcludeRule, prefix string) excludeRule {
173
133
return parsedRule
174
134
}
175
135
136
+ func (e excludeRule ) String () string {
137
+ var msg []string
138
+
139
+ if e .text != nil && e .text .String () != "" {
140
+ msg = append (msg , fmt .Sprintf ("Text: %q" , e .text ))
141
+ }
142
+
143
+ if e .source != nil && e .source .String () != "" {
144
+ msg = append (msg , fmt .Sprintf ("Source: %q" , e .source ))
145
+ }
146
+
147
+ if e .path != nil && e .path .String () != "" {
148
+ msg = append (msg , fmt .Sprintf ("Path: %q" , e .path ))
149
+ }
150
+
151
+ if e .pathExcept != nil && e .pathExcept .String () != "" {
152
+ msg = append (msg , fmt .Sprintf ("Path Except: %q" , e .pathExcept ))
153
+ }
154
+
155
+ if len (e .linters ) > 0 {
156
+ msg = append (msg , fmt .Sprintf ("Linters: %q" , strings .Join (e .linters , ", " )))
157
+ }
158
+
159
+ return strings .Join (msg , ", " )
160
+ }
161
+
162
+ func createExcludeRules (rules []config.ExcludeRule , prefix string ) []excludeRule {
163
+ if len (rules ) == 0 {
164
+ return nil
165
+ }
166
+
167
+ parsedRules := make ([]excludeRule , 0 , len (rules ))
168
+
169
+ for _ , rule := range rules {
170
+ parsedRules = append (parsedRules , newRule (& rule , prefix ))
171
+ }
172
+
173
+ return parsedRules
174
+ }
175
+
176
176
// TODO(ldez): must be removed in v2, only for compatibility with exclude-use-default/include.
177
177
func filterInclude (rules []config.ExcludeRule , refs []string ) []config.ExcludeRule {
178
178
if len (refs ) == 0 {
0 commit comments