@@ -263,46 +263,52 @@ func (c *Config) ExcludePath(path string) bool {
263
263
func (c * Config ) ShouldGenerateInterface (ctx context.Context , packageName , interfaceName string ) (bool , error ) {
264
264
pkgConfig , err := c .GetPackageConfig (ctx , packageName )
265
265
if err != nil {
266
- return false , err
266
+ return false , fmt .Errorf ("getting package config: %w" , err )
267
+ }
268
+
269
+ log := zerolog .Ctx (ctx )
270
+ if pkgConfig .All {
271
+ if pkgConfig .IncludeRegex != "" {
272
+ log .Warn ().Msg ("interface config has both `all` and `include-regex` set: `include-regex` will be ignored" )
273
+ }
274
+ if pkgConfig .ExcludeRegex != "" {
275
+ log .Warn ().Msg ("interface config has both `all` and `exclude-regex` set: `exclude-regex` will be ignored" )
276
+ }
277
+ return true , nil
267
278
}
268
279
269
280
interfacesSection , err := c .getInterfacesSection (ctx , packageName )
270
281
if err != nil {
271
- return false , err
282
+ return false , fmt . Errorf ( "getting interfaces section: %w" , err )
272
283
}
273
284
_ , interfaceExists := interfacesSection [interfaceName ]
274
-
275
- matchedByRegex := false
276
- if pkgConfig .IncludeRegex != "" {
277
- if pkgConfig .All {
278
- log := zerolog .Ctx (ctx )
279
- log .Warn ().Msg ("interface config has both `all` and `include-regex` set: `include-regex` will be ignored" )
280
- } else {
281
- matchedByRegex , err = regexp .MatchString (pkgConfig .IncludeRegex , interfaceName )
282
- if err != nil {
283
- return false , fmt .Errorf ("evaluating `include-regex`: %w" , err )
284
- }
285
- }
285
+ if interfaceExists {
286
+ return true , nil
286
287
}
287
- excludedByRegex := false
288
- if pkgConfig .ExcludeRegex != "" {
289
- if pkgConfig .All {
290
- log := zerolog .Ctx (ctx )
291
- log .Warn ().Msg ("interface config has both `all` and `exclude-regex` set: `exclude-regex` will be ignored" )
292
- } else if pkgConfig .IncludeRegex == "" {
293
- log := zerolog .Ctx (ctx )
288
+
289
+ includeRegex := pkgConfig .IncludeRegex
290
+ excludeRegex := pkgConfig .ExcludeRegex
291
+ if includeRegex == "" {
292
+ if excludeRegex != "" {
294
293
log .Warn ().Msg ("interface config has `exclude-regex` set but not `include-regex`: `exclude-regex` will be ignored" )
295
- } else {
296
- excludedByRegex , err = regexp .MatchString (pkgConfig .ExcludeRegex , interfaceName )
297
- if err != nil {
298
- return false , fmt .Errorf ("evaluating `exclude-regex`: %w" , err )
299
- }
300
- if excludedByRegex {
301
- matchedByRegex = false
302
- }
303
294
}
295
+ return false , nil
296
+ }
297
+ includedByRegex , err := regexp .MatchString (includeRegex , interfaceName )
298
+ if err != nil {
299
+ return false , fmt .Errorf ("evaluating `include-regex`: %w" , err )
300
+ }
301
+ if ! includedByRegex {
302
+ return false , nil
303
+ }
304
+ if excludeRegex == "" {
305
+ return true , nil
306
+ }
307
+ excludedByRegex , err := regexp .MatchString (excludeRegex , interfaceName )
308
+ if err != nil {
309
+ return false , fmt .Errorf ("evaluating `exclude-regex`: %w" , err )
304
310
}
305
- return pkgConfig . All || interfaceExists || ( matchedByRegex && ! excludedByRegex ) , nil
311
+ return ! excludedByRegex , nil
306
312
}
307
313
308
314
func (c * Config ) getInterfacesSection (ctx context.Context , packageName string ) (map [string ]any , error ) {
0 commit comments