Skip to content

Commit 6a292eb

Browse files
committed
Rename include/exclude-regex to be more specific and clear.
1 parent 08ce0bb commit 6a292eb

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

.mockery_matryer.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ packages:
1212
github.com/vektra/mockery/v3/internal/fixtures:
1313
config:
1414
all: false
15-
include-regex: '.*'
16-
exclude-regex: 'RequesterGenerics'
15+
include-interface-regex: '.*'
16+
exclude-interface-regex: 'RequesterGenerics'
1717
interfaces:
1818
Requester:
1919
configs:

config/config.go

+28-28
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ func (c PackageConfig) GetInterfaceConfig(ctx context.Context, interfaceName str
418418
func (c PackageConfig) ShouldGenerateInterface(ctx context.Context, interfaceName string) (bool, error) {
419419
log := zerolog.Ctx(ctx)
420420
if *c.Config.All {
421-
if *c.Config.IncludeRegex != "" {
422-
log.Warn().Msg("interface config has both `all` and `include-regex` set: `include-regex` will be ignored")
421+
if *c.Config.IncludeInterfaceRegex != "" {
422+
log.Warn().Msg("interface config has both `all` and `include-interface-regex` set: `include-interface-regex` will be ignored")
423423
}
424-
if *c.Config.ExcludeRegex != "" {
425-
log.Warn().Msg("interface config has both `all` and `exclude-regex` set: `exclude-regex` will be ignored")
424+
if *c.Config.ExcludeInterfaceRegex != "" {
425+
log.Warn().Msg("interface config has both `all` and `exclude-interface-regex` set: `exclude-interface-regex` will be ignored")
426426
}
427427
log.Debug().Msg("`all: true` is set, interface should be generated")
428428
return true, nil
@@ -432,35 +432,35 @@ func (c PackageConfig) ShouldGenerateInterface(ctx context.Context, interfaceNam
432432
return true, nil
433433
}
434434

435-
includeRegex := *c.Config.IncludeRegex
436-
excludeRegex := *c.Config.ExcludeRegex
435+
includeRegex := *c.Config.IncludeInterfaceRegex
436+
excludeRegex := *c.Config.ExcludeInterfaceRegex
437437
if includeRegex == "" {
438438
if excludeRegex != "" {
439-
log.Warn().Msg("interface config has `exclude-regex` set but not `include-regex`: `exclude-regex` will be ignored")
439+
log.Warn().Msg("interface config has `exclude-interface-regex` set but not `include-interface-regex`: `exclude-interface-regex` will be ignored")
440440
}
441441
return false, nil
442442
}
443443
includedByRegex, err := regexp.MatchString(includeRegex, interfaceName)
444444
if err != nil {
445-
return false, fmt.Errorf("evaluating `include-regex`: %w", err)
445+
return false, fmt.Errorf("evaluating `include-interface-regex`: %w", err)
446446
}
447447
if !includedByRegex {
448-
log.Debug().Msg("interface does not match include-regex")
448+
log.Debug().Msg("interface does not match include-interface-regex")
449449
return false, nil
450450
}
451-
log.Debug().Msg("interface matches include-regex")
451+
log.Debug().Msg("interface matches include-interface-regex")
452452
if excludeRegex == "" {
453453
return true, nil
454454
}
455455
excludedByRegex, err := regexp.MatchString(excludeRegex, interfaceName)
456456
if err != nil {
457-
return false, fmt.Errorf("evaluating `exclude-regex`: %w", err)
457+
return false, fmt.Errorf("evaluating `exclude-interface-regex`: %w", err)
458458
}
459459
if excludedByRegex {
460-
log.Debug().Msg("interface matches exclude-regex")
460+
log.Debug().Msg("interface matches exclude-interface-regex")
461461
return false, nil
462462
}
463-
log.Debug().Msg("interface does not match exclude-regex")
463+
log.Debug().Msg("interface does not match exclude-interface-regex")
464464
return true, nil
465465
}
466466

@@ -494,22 +494,22 @@ type ReplaceType struct {
494494
}
495495

496496
type Config struct {
497-
All *bool `koanf:"all" yaml:"all,omitempty"`
498-
Anchors map[string]any `koanf:"_anchors" yaml:"_anchors,omitempty"`
499-
BuildTags *string `koanf:"build-tags" yaml:"build-tags,omitempty"`
500-
ConfigFile *string `koanf:"config" yaml:"config,omitempty"`
501-
Dir *string `koanf:"dir" yaml:"dir,omitempty"`
502-
ExcludeSubpkgRegex []string `koanf:"exclude-subpkg-regex" yaml:"exclude-subpkg-regex,omitempty"`
503-
ExcludeRegex *string `koanf:"exclude-regex" yaml:"exclude-regex,omitempty"`
504-
FileName *string `koanf:"filename" yaml:"filename,omitempty"`
497+
All *bool `koanf:"all" yaml:"all,omitempty"`
498+
Anchors map[string]any `koanf:"_anchors" yaml:"_anchors,omitempty"`
499+
BuildTags *string `koanf:"build-tags" yaml:"build-tags,omitempty"`
500+
ConfigFile *string `koanf:"config" yaml:"config,omitempty"`
501+
Dir *string `koanf:"dir" yaml:"dir,omitempty"`
502+
ExcludeSubpkgRegex []string `koanf:"exclude-subpkg-regex" yaml:"exclude-subpkg-regex,omitempty"`
503+
ExcludeInterfaceRegex *string `koanf:"exclude-interface-regex" yaml:"exclude-interface-regex,omitempty"`
504+
FileName *string `koanf:"filename" yaml:"filename,omitempty"`
505505
// ForceFileWrite controls whether mockery will overwrite existing files when generating mocks. This is by default set to false.
506-
ForceFileWrite *bool `koanf:"force-file-write" yaml:"force-file-write,omitempty"`
507-
Formatter *string `koanf:"formatter" yaml:"formatter,omitempty"`
508-
IncludeRegex *string `koanf:"include-regex" yaml:"include-regex,omitempty"`
509-
LogLevel *string `koanf:"log-level" yaml:"log-level,omitempty"`
510-
StructName *string `koanf:"structname" yaml:"structname,omitempty"`
511-
PkgName *string `koanf:"pkgname" yaml:"pkgname,omitempty"`
512-
Recursive *bool `koanf:"recursive" yaml:"recursive,omitempty"`
506+
ForceFileWrite *bool `koanf:"force-file-write" yaml:"force-file-write,omitempty"`
507+
Formatter *string `koanf:"formatter" yaml:"formatter,omitempty"`
508+
IncludeInterfaceRegex *string `koanf:"include-interface-regex" yaml:"include-interface-regex,omitempty"`
509+
LogLevel *string `koanf:"log-level" yaml:"log-level,omitempty"`
510+
StructName *string `koanf:"structname" yaml:"structname,omitempty"`
511+
PkgName *string `koanf:"pkgname" yaml:"pkgname,omitempty"`
512+
Recursive *bool `koanf:"recursive" yaml:"recursive,omitempty"`
513513
// ReplaceType is a nested map of format map["package path"]["type name"]*ReplaceType
514514
ReplaceType map[string]map[string]*ReplaceType `koanf:"replace-type" yaml:"replace-type,omitempty"`
515515
// RequireTemplateSchemaExists sets whether mockery will fail if the specified

docs/configuration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ Parameter Descriptions
121121
| `config` | :fontawesome-solid-x: | `#!yaml ""` | Set the location of the mockery config file. |
122122
| `dir` | :fontawesome-solid-check: | `#!yaml "mocks/{{.SrcPackagePath}}"` | The directory where the mock file will be outputted to. |
123123
| `exclude-subpkg-regex` | :fontawesome-solid-x: | `#!yaml []` | A list of regular expressions that denote which subpackages should be excluded when `#!yaml recursive: true` |
124-
| `exclude-regex` | :fontawesome-solid-x: | `#!yaml ""` | When set along with `include-regex`, then interfaces which match `include-regex` but also match `exclude-regex` will not be generated. If `all` is set, or if `include-regex` is not set, then `exclude-regex` has no effect. |
124+
| `exclude-interface-regex` | :fontawesome-solid-x: | `#!yaml ""` | When set along with `include-interface-regex`, then interfaces which match `include-interface-regex` but also match `exclude-interface-regex` will not be generated. If `all` is set, or if `include-interface-regex` is not set, then `exclude-interface-regex` has no effect. |
125125
| `filename` | :fontawesome-solid-check: | `#!yaml "mock_{{.InterfaceName}}.go"` | The name of the file the mock will reside in. |
126126
| `force-file-write` | :fontawesome-solid-x: | `#!yaml false` | When set to `#!yaml force-file-write: true`, mockery will forcibly overwrite any existing files. |
127127
| `formatter` | :fontawesome-solid-x: | `#!yaml "goimports"` | The formatter to use on the rendered template. Choices are: `gofmt`, `goimports`, `noop`. |
128-
| `include-regex` | :fontawesome-solid-x: | `#!yaml ""` | When set, only interface names that match the expression will be generated. This setting is ignored if `all: True` is specified in the configuration. To further refine the interfaces generated, use `exclude-regex`. |
128+
| `include-interface-regex` | :fontawesome-solid-x: | `#!yaml ""` | When set, only interface names that match the expression will be generated. This setting is ignored if `all: True` is specified in the configuration. To further refine the interfaces generated, use `exclude-interface-regex`. |
129129
| `log-level` | :fontawesome-solid-x: | `#!yaml "info"` | Set the level of the logger |
130130
| `structname` | :fontawesome-solid-check: | `#!yaml "Mock{{.InterfaceName}}"` | The name of the generated interface implementation. |
131131
| `packages` | :fontawesome-solid-x: | `#!yaml null` | A dictionary containing configuration describing the packages and interfaces to generate mocks for. |

internal/cmd/migrate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func migrateConfig(
326326
tbl.Append("deprecated-parameter", "`dry-run` not supported in v3.")
327327
}
328328
v3.ExcludeSubpkgRegex = v2Config.Exclude
329-
v3.ExcludeRegex = v2Config.ExcludeRegex
329+
v3.ExcludeInterfaceRegex = v2Config.ExcludeRegex
330330
if v2Config.Exported != nil {
331331
tbl.Append("deprecated-parameter", "`exported` is no longer supported. Use `structname` instead.")
332332
}
@@ -340,7 +340,7 @@ func migrateConfig(
340340
if v2Config.IncludeAutoGenerated != nil && *v2Config.IncludeAutoGenerated == false {
341341
tbl.Append("deprecated-parameter", "`include-auto-generated` is not supported in v3, but PRs are welcome: https://github.com/vektra/mockery/issues/954")
342342
}
343-
v3.IncludeRegex = v2Config.IncludeRegex
343+
v3.IncludeInterfaceRegex = v2Config.IncludeRegex
344344
if v2Config.Issue845Fix == nil || *v2Config.Issue845Fix == false {
345345
tbl.Append("deprecated-parameter", "`issue-845-fix` is permanently set to True in v3.")
346346
}

0 commit comments

Comments
 (0)