@@ -14,36 +14,6 @@ import (
1414
1515var _ Processor = (* ExclusionRules )(nil )
1616
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-
4717type ExclusionRules struct {
4818 log logutils.Log
4919 files * fsutils.Files
@@ -68,18 +38,18 @@ func NewExclusionRules(log logutils.Log, files *fsutils.Files, cfg *config.Linte
6838 prefix = ""
6939 }
7040
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 ))
7343
74- p .rules = createRules (excludeRules , prefix )
44+ p .rules = createExcludeRules (excludeRules , prefix )
7545
7646 // TODO(ldez): should be removed in v2.
7747 for _ , pattern := range oldCfg .ExcludePatterns {
7848 if pattern == "" {
7949 continue
8050 }
8151
82- rule := createRule (& config.ExcludeRule {
52+ rule := newRule (& config.ExcludeRule {
8353 BaseRule : config.BaseRule {
8454 Path : `.+\.go` ,
8555 Text : pattern ,
@@ -135,21 +105,11 @@ func (p *ExclusionRules) Finish() {
135105 }
136106}
137107
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
150110}
151111
152- func createRule (rule * config.ExcludeRule , prefix string ) excludeRule {
112+ func newRule (rule * config.ExcludeRule , prefix string ) excludeRule {
153113 parsedRule := excludeRule {}
154114 parsedRule .linters = rule .Linters
155115 parsedRule .internalReference = rule .InternalReference
@@ -173,6 +133,46 @@ func createRule(rule *config.ExcludeRule, prefix string) excludeRule {
173133 return parsedRule
174134}
175135
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+
176176// TODO(ldez): must be removed in v2, only for compatibility with exclude-use-default/include.
177177func filterInclude (rules []config.ExcludeRule , refs []string ) []config.ExcludeRule {
178178 if len (refs ) == 0 {
0 commit comments