From 97b8ded1f7b9aafec1b7d06b164bae6a1aa5357f Mon Sep 17 00:00:00 2001
From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com>
Date: Mon, 13 Jan 2025 22:45:42 -0600
Subject: [PATCH 1/7] Add enhanced deprecation logging support.
This commit adds the ability to silence particular deprecation messages. It also
resolved #893.
---
cmd/mockery.go | 17 +++++++--
docs/configuration.md | 12 ++++---
docs/deprecations.md | 21 +++++++++---
pkg/config/config.go | 78 ++++++++++++++++++++++--------------------
pkg/generator.go | 2 ++
pkg/logging/logging.go | 25 +++++++++++---
6 files changed, 101 insertions(+), 54 deletions(-)
diff --git a/cmd/mockery.go b/cmd/mockery.go
index 4cccae4a..fe1862fc 100644
--- a/cmd/mockery.go
+++ b/cmd/mockery.go
@@ -196,6 +196,9 @@ func (r *RootApp) Run() error {
fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
return err
}
+ logging.DisableDeprecationWarnings = r.Config.DisableDeprecationWarnings
+ logging.DisabledDeprecationWarnings = r.Config.DisabledDeprecationWarnings
+
log = log.With().Bool(logging.LogKeyDryRun, r.Config.DryRun).Logger()
log.Info().Msgf("Starting mockery")
log.Info().Msgf("Using config: %s", r.Config.Config)
@@ -231,10 +234,17 @@ func (r *RootApp) Run() error {
if !r.Config.WithExpecter {
logging.WarnDeprecated(
ctx,
+ "with-expecter",
"with-expecter will be permanently set to True in v3",
- map[string]any{
- "url": logging.DocsURL("/deprecations/#with-expecter"),
- },
+ nil,
+ )
+ }
+ if r.Config.Quiet {
+ logging.WarnDeprecated(
+ ctx,
+ "quiet",
+ "The --quiet parameter will be removed in v3. Use --log-level=\"\" instead",
+ nil,
)
}
@@ -311,6 +321,7 @@ func (r *RootApp) Run() error {
logging.WarnDeprecated(
ctx,
+ "packages",
"use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
map[string]any{
"url": logging.DocsURL("/features/#packages-configuration"),
diff --git a/docs/configuration.md b/docs/configuration.md
index 18908133..aff32fa3 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -1,7 +1,7 @@
Configuration
==============
-mockery uses [spf13/viper](https://github.com/spf13/viper) under the hood for its configuration parsing.
+mockery uses [spf13/viper](https://github.com/spf13/viper) under the hood for its configuration parsing.
Merging Precedence
------------------
@@ -64,6 +64,8 @@ Parameter Descriptions
| `config` | :fontawesome-solid-x: | `#!yaml ""` | Set the location of the mockery config file. |
| `dir` | :fontawesome-solid-check: | `#!yaml "mocks/{{.PackagePath}}"` | The directory where the mock file will be outputted to. |
| `disable-config-search` | :fontawesome-solid-x: | `#!yaml false` | Disable searching for configuration files |
+| `disable-deprecation-warnings` | :fontawesome-solid-x: | `#!yaml false` | Disable all warnings for deprecated behavior. |
+| `disabled-deprecation-warnings` | :fontawesome-solid-x: | `#!yaml []` | A list of strings that will selectively disable certain deprecation warnings. The name of each warning is given in the `deprecation-name` attribute of the log message. |
| `disable-func-mocks` | :fontawesome-solid-x: | `#!yaml false` | Disable generation of function mocks. |
| `disable-version-string` | :fontawesome-solid-x: | `#!yaml false` | Disable the version string in the generated mock files. |
| `dry-run` | :fontawesome-solid-x: | `#!yaml false` | Print the actions that would be taken, but don't perform the actions. |
@@ -130,7 +132,7 @@ Using different configuration parameters, we can deploy our mocks on-disk in var
}
```
=== "adjacent to interface"
-
+
!!! warning
Mockery does not protect against modifying original source code. Do not generate mocks using this config with uncommitted code changes.
@@ -186,7 +188,7 @@ Using different configuration parameters, we can deploy our mocks on-disk in var
Templated Strings
------------------
-mockery configuration makes use of the Go templating system.
+mockery configuration makes use of the Go templating system.
### Variables
@@ -202,7 +204,7 @@ Variables that are marked as being templated are capable of using mockery-provid
| InterfaceDirRelative | The directory path of the original interface being mocked, relative to the current working directory. If the path cannot be made relative to the current working directory, this variable will be set equal to `PackagePath` |
| InterfaceFile | The file path of the original interface being mocked. **NOTE:** This option will only write one mock implementation to the output file. If multiple mocks are defined in your original file, only one mock will be written to the output. |
| InterfaceName | The name of the original interface being mocked |
-| InterfaceNameCamel | Converts a string `interface_name` to `InterfaceName`.
DEPRECATED: use `{{ .InterfaceName | camelcase }}` instead |
+| InterfaceNameCamel | Converts a string `interface_name` to `InterfaceName`.
DEPRECATED: use `{{ .InterfaceName | camelcase }}` instead |
| InterfaceNameLowerCamel | Converts `InterfaceName` to `interfaceName` .
DEPRECATED: use `{{ .InterfaceName | camelcase | firstLower }}` instead |
| InterfaceNameSnake | Converts `InterfaceName` to `interface_name` .
DEPRECATED: use `{{ .InterfaceName | snakecase }}` instead |
| InterfaceNameLower | Converts `InterfaceName` to `interfacename` .
DEPRECATED: use `{{ .InterfaceName | lower }}` instead |
@@ -258,7 +260,7 @@ Legacy config options
??? danger "legacy configuration options"
The legacy config options will be removed in v3 and are deprecated (but supported) in v2.
-
+
| name | description |
|------|-------------|
| `all` | It's common for a big package to have a lot of interfaces, so mockery provides `all`. This option will tell mockery to scan all files under the directory named by `--dir` ("." by default) and generates mocks for any interfaces it finds. This option implies `recursive: True`. |
diff --git a/docs/deprecations.md b/docs/deprecations.md
index 3c7b699b..9d92685e 100644
--- a/docs/deprecations.md
+++ b/docs/deprecations.md
@@ -21,7 +21,7 @@ The [`packages`](features.md#packages-configuration) feature will be the only wa
!!! tip ""
To resolve this warning:
-
+
```yaml title=".mockery.yaml"
issue-845-fix: True
```
@@ -60,7 +60,7 @@ if being generated with `#!yaml inpackage: True`.
!!! tip ""
To resolve this warning:
-
+
```yaml title=".mockery.yaml"
resolve-type-alias: False
```
@@ -84,10 +84,23 @@ be set to `False`. This will be the permanent behavior in Mockery v3.
!!! tip ""
To resolve this warning:
-
+
```yaml title=".mockery.yaml"
with-expecter: True
```
This parameter enables the [expecter structs](features.md#expecter-structs). In Mockery v3, this parameter will be permanently
-enabled. In order to remove the deprecation warning, you must set this parameter to `#!yaml with-expecter: True`.
\ No newline at end of file
+enabled. In order to remove the deprecation warning, you must set this parameter to `#!yaml with-expecter: True`.
+
+`quiet`
+-------
+
+!!! tip ""
+
+ To resolve this warning:
+
+ ```yaml title=".mockery.yaml"
+ quiet: False
+ ```
+
+The `--quiet` parameter is superseded by `--log-level=""`. It will be removed in v3.
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 72b231e3..0f568de6 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -32,44 +32,46 @@ type Interface struct {
}
type Config struct {
- All bool `mapstructure:"all"`
- Anchors map[string]any `mapstructure:"_anchors"`
- BoilerplateFile string `mapstructure:"boilerplate-file"`
- BuildTags string `mapstructure:"tags"`
- Case string `mapstructure:"case"`
- Config string `mapstructure:"config"`
- Cpuprofile string `mapstructure:"cpuprofile"`
- Dir string `mapstructure:"dir"`
- DisableConfigSearch bool `mapstructure:"disable-config-search"`
- DisableFuncMocks bool `mapstructure:"disable-func-mocks"`
- DisableVersionString bool `mapstructure:"disable-version-string"`
- DryRun bool `mapstructure:"dry-run"`
- Exclude []string `mapstructure:"exclude"`
- ExcludeRegex string `mapstructure:"exclude-regex"`
- Exported bool `mapstructure:"exported"`
- FileName string `mapstructure:"filename"`
- InPackage bool `mapstructure:"inpackage"`
- InPackageSuffix bool `mapstructure:"inpackage-suffix"`
- IncludeAutoGenerated bool `mapstructure:"include-auto-generated"`
- IncludeRegex string `mapstructure:"include-regex"`
- Issue845Fix bool `mapstructure:"issue-845-fix"`
- KeepTree bool `mapstructure:"keeptree"`
- LogLevel string `mapstructure:"log-level"`
- MockBuildTags string `mapstructure:"mock-build-tags"`
- MockName string `mapstructure:"mockname"`
- Name string `mapstructure:"name"`
- Note string `mapstructure:"note"`
- Outpkg string `mapstructure:"outpkg"`
- Output string `mapstructure:"output"`
- Packageprefix string `mapstructure:"packageprefix"`
- Packages map[string]interface{} `mapstructure:"packages"`
- Print bool `mapstructure:"print"`
- Profile string `mapstructure:"profile"`
- Quiet bool `mapstructure:"quiet"`
- Recursive bool `mapstructure:"recursive"`
- ReplaceType []string `mapstructure:"replace-type"`
- ResolveTypeAlias bool `mapstructure:"resolve-type-alias"`
- SrcPkg string `mapstructure:"srcpkg"`
+ All bool `mapstructure:"all"`
+ Anchors map[string]any `mapstructure:"_anchors"`
+ BoilerplateFile string `mapstructure:"boilerplate-file"`
+ BuildTags string `mapstructure:"tags"`
+ Case string `mapstructure:"case"`
+ Config string `mapstructure:"config"`
+ Cpuprofile string `mapstructure:"cpuprofile"`
+ Dir string `mapstructure:"dir"`
+ DisableConfigSearch bool `mapstructure:"disable-config-search"`
+ DisableDeprecationWarnings bool `mapstructure:"disable-deprecation-warnings"`
+ DisabledDeprecationWarnings []string `mapstructure:"disabled-deprecation-warnings"`
+ DisableFuncMocks bool `mapstructure:"disable-func-mocks"`
+ DisableVersionString bool `mapstructure:"disable-version-string"`
+ DryRun bool `mapstructure:"dry-run"`
+ Exclude []string `mapstructure:"exclude"`
+ ExcludeRegex string `mapstructure:"exclude-regex"`
+ Exported bool `mapstructure:"exported"`
+ FileName string `mapstructure:"filename"`
+ InPackage bool `mapstructure:"inpackage"`
+ InPackageSuffix bool `mapstructure:"inpackage-suffix"`
+ IncludeAutoGenerated bool `mapstructure:"include-auto-generated"`
+ IncludeRegex string `mapstructure:"include-regex"`
+ Issue845Fix bool `mapstructure:"issue-845-fix"`
+ KeepTree bool `mapstructure:"keeptree"`
+ LogLevel string `mapstructure:"log-level"`
+ MockBuildTags string `mapstructure:"mock-build-tags"`
+ MockName string `mapstructure:"mockname"`
+ Name string `mapstructure:"name"`
+ Note string `mapstructure:"note"`
+ Outpkg string `mapstructure:"outpkg"`
+ Output string `mapstructure:"output"`
+ Packageprefix string `mapstructure:"packageprefix"`
+ Packages map[string]interface{} `mapstructure:"packages"`
+ Print bool `mapstructure:"print"`
+ Profile string `mapstructure:"profile"`
+ Quiet bool `mapstructure:"quiet"`
+ Recursive bool `mapstructure:"recursive"`
+ ReplaceType []string `mapstructure:"replace-type"`
+ ResolveTypeAlias bool `mapstructure:"resolve-type-alias"`
+ SrcPkg string `mapstructure:"srcpkg"`
// StructName overrides the name given to the mock struct and should only be nonempty
// when generating for an exact match (non regex expression in -name).
StructName string `mapstructure:"structname"`
diff --git a/pkg/generator.go b/pkg/generator.go
index bcda68cb..a0d75395 100644
--- a/pkg/generator.go
+++ b/pkg/generator.go
@@ -426,6 +426,7 @@ func (g *Generator) GeneratePrologue(ctx context.Context, pkg string) {
if !g.config.Issue845Fix {
logging.WarnDeprecated(
ctx,
+ "issue-845-fix",
"issue-845-fix must be set to True to remove this warning. Visit the link for more details.",
map[string]any{
"url": logging.DocsURL("/deprecations/#issue-845-fix"),
@@ -542,6 +543,7 @@ func (g *Generator) renderType(ctx context.Context, typ types.Type) string {
if g.config.ResolveTypeAlias {
logging.WarnDeprecated(
ctx,
+ "resolve-type-alias",
"resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False.",
map[string]any{
"url": logging.DocsURL("/deprecations/#resolve-type-alias"),
diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go
index ca266758..01d88f57 100644
--- a/pkg/logging/logging.go
+++ b/pkg/logging/logging.go
@@ -28,8 +28,11 @@ const (
defaultSemVer = "v0.0.0-dev"
)
-// SemVer is the version of mockery at build time.
-var SemVer = ""
+var (
+ SemVer = ""
+ DisableDeprecationWarnings bool
+ DisabledDeprecationWarnings []string
+)
var ErrPkgNotExist = errors.New("package does not exist")
@@ -86,7 +89,6 @@ func GetLogger(levelStr string) (zerolog.Logger, error) {
With().
Str("version", GetSemverInfo()).
Logger()
-
return log, nil
}
@@ -108,6 +110,21 @@ func Info(ctx context.Context, prefix string, message string, fields map[string]
event.Msgf("%s: %s", prefix, message)
}
-func WarnDeprecated(ctx context.Context, message string, fields map[string]any) {
+func WarnDeprecated(ctx context.Context, name, message string, fields map[string]any) {
+ if DisableDeprecationWarnings {
+ return
+ }
+ for _, disabledWarning := range DisabledDeprecationWarnings {
+ if disabledWarning == name {
+ return
+ }
+ }
+ if fields == nil {
+ fields = map[string]any{}
+ }
+ fields["deprecation-name"] = name
+ if _, ok := fields["url"]; !ok {
+ fields["url"] = DocsURL(fmt.Sprintf("/deprecations/#%s", name))
+ }
Warn(ctx, "DEPRECATION", message, fields)
}
From eedf64dc45f4e44169dae6a6b88f1dbfd24afe6c Mon Sep 17 00:00:00 2001
From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com>
Date: Mon, 13 Jan 2025 22:54:17 -0600
Subject: [PATCH 2/7] Organize deprecations
---
cmd/mockery.go | 28 +++++++++++++++++++---------
pkg/generator.go | 8 --------
2 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/cmd/mockery.go b/cmd/mockery.go
index fe1862fc..5ecbc837 100644
--- a/cmd/mockery.go
+++ b/cmd/mockery.go
@@ -247,6 +247,25 @@ func (r *RootApp) Run() error {
nil,
)
}
+ if r.Config.ResolveTypeAlias {
+ logging.WarnDeprecated(
+ ctx,
+ "resolve-type-alias",
+ "resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False.",
+ nil,
+ )
+ }
+ if r.Config.Packages == nil {
+ logging.WarnDeprecated(
+ ctx,
+ "packages",
+ "use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
+ map[string]any{
+ "url": logging.DocsURL("/features/#packages-configuration"),
+ "migration": logging.DocsURL("/migrating_to_packages/"),
+ },
+ )
+ }
configuredPackages, err := r.Config.GetPackages(ctx)
if err != nil && !errors.Is(err, os.ErrNotExist) {
@@ -319,15 +338,6 @@ func (r *RootApp) Run() error {
log.Fatal().Msgf("Use --name to specify the name of the interface or --all for all interfaces found")
}
- logging.WarnDeprecated(
- ctx,
- "packages",
- "use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
- map[string]any{
- "url": logging.DocsURL("/features/#packages-configuration"),
- "migration": logging.DocsURL("/migrating_to_packages/"),
- })
-
if r.Config.Profile != "" {
f, err := os.Create(r.Config.Profile)
if err != nil {
diff --git a/pkg/generator.go b/pkg/generator.go
index a0d75395..58d54865 100644
--- a/pkg/generator.go
+++ b/pkg/generator.go
@@ -541,14 +541,6 @@ func (g *Generator) renderType(ctx context.Context, typ types.Type) string {
case *types.Alias:
log.Debug().Msg("found type alias")
if g.config.ResolveTypeAlias {
- logging.WarnDeprecated(
- ctx,
- "resolve-type-alias",
- "resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False.",
- map[string]any{
- "url": logging.DocsURL("/deprecations/#resolve-type-alias"),
- },
- )
return g.renderType(ctx, t.Rhs())
}
log.Debug().Msg("not resolving type alias to underlying type")
From 7df0754b2de6417e171b8d9c5c6c9ed1e2f86e88 Mon Sep 17 00:00:00 2001
From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com>
Date: Mon, 13 Jan 2025 23:03:21 -0600
Subject: [PATCH 3/7] Add dep warn for `disable-version-string`
Resolves #872.
---
cmd/mockery.go | 24 ------------------------
docs/deprecations.md | 12 ++++++++++++
pkg/config/config.go | 35 +++++++++++++++++++++++++++++++++++
pkg/generator.go | 10 ++++++++++
pkg/logging/logging.go | 7 +++++++
pkg/outputter.go | 1 +
6 files changed, 65 insertions(+), 24 deletions(-)
diff --git a/cmd/mockery.go b/cmd/mockery.go
index 5ecbc837..ede49443 100644
--- a/cmd/mockery.go
+++ b/cmd/mockery.go
@@ -231,30 +231,6 @@ func (r *RootApp) Run() error {
boilerplate = string(data)
}
- if !r.Config.WithExpecter {
- logging.WarnDeprecated(
- ctx,
- "with-expecter",
- "with-expecter will be permanently set to True in v3",
- nil,
- )
- }
- if r.Config.Quiet {
- logging.WarnDeprecated(
- ctx,
- "quiet",
- "The --quiet parameter will be removed in v3. Use --log-level=\"\" instead",
- nil,
- )
- }
- if r.Config.ResolveTypeAlias {
- logging.WarnDeprecated(
- ctx,
- "resolve-type-alias",
- "resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False.",
- nil,
- )
- }
if r.Config.Packages == nil {
logging.WarnDeprecated(
ctx,
diff --git a/docs/deprecations.md b/docs/deprecations.md
index 9d92685e..edde9bb3 100644
--- a/docs/deprecations.md
+++ b/docs/deprecations.md
@@ -104,3 +104,15 @@ enabled. In order to remove the deprecation warning, you must set this parameter
```
The `--quiet` parameter is superseded by `--log-level=""`. It will be removed in v3.
+
+`disable-version-string`
+-----------------------
+!!! tip ""
+
+ To resolve this warning:
+
+ ```yaml title=".mockery.yaml"
+ disable-version-string: True
+ ```
+
+Mockery will no longer print the version of mockery used as a comment in the mock files.
\ No newline at end of file
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 0f568de6..3378e061 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -827,3 +827,38 @@ func (c *Config) LogUnsupportedPackagesConfig(ctx context.Context) {
Logger()
l.Error().Msg("use of unsupported options detected. mockery behavior is undefined.")
}
+
+func (c *Config) LogDeprecatedConfig(ctx context.Context) {
+ if !c.WithExpecter {
+ logging.WarnDeprecated(
+ ctx,
+ "with-expecter",
+ "with-expecter will be permanently set to True in v3",
+ nil,
+ )
+ }
+ if c.Quiet {
+ logging.WarnDeprecated(
+ ctx,
+ "quiet",
+ "The --quiet parameter will be removed in v3. Use --log-level=\"\" instead",
+ nil,
+ )
+ }
+ if c.ResolveTypeAlias {
+ logging.WarnDeprecated(
+ ctx,
+ "resolve-type-alias",
+ "resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False.",
+ nil,
+ )
+ }
+ if c.DisableVersionString {
+ logging.WarnDeprecated(
+ ctx,
+ "disable-version-string",
+ "disable-version-string will be permanently set to True in v3",
+ nil,
+ )
+ }
+}
diff --git a/pkg/generator.go b/pkg/generator.go
index 58d54865..4525cd60 100644
--- a/pkg/generator.go
+++ b/pkg/generator.go
@@ -541,6 +541,16 @@ func (g *Generator) renderType(ctx context.Context, typ types.Type) string {
case *types.Alias:
log.Debug().Msg("found type alias")
if g.config.ResolveTypeAlias {
+ // Technically, this log message is duplicated from when we call it in cmd/mockery.go. That's
+ // needed because each interface can have different values for this parameter.
+ logging.WarnDeprecated(
+ ctx,
+ "resolve-type-alias",
+ "resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False.",
+ map[string]any{
+ "url": logging.DocsURL("/deprecations/#resolve-type-alias"),
+ },
+ )
return g.renderType(ctx, t.Rhs())
}
log.Debug().Msg("not resolving type alias to underlying type")
diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go
index 01d88f57..23bdd5c7 100644
--- a/pkg/logging/logging.go
+++ b/pkg/logging/logging.go
@@ -32,6 +32,7 @@ var (
SemVer = ""
DisableDeprecationWarnings bool
DisabledDeprecationWarnings []string
+ seenWarnings []string
)
var ErrPkgNotExist = errors.New("package does not exist")
@@ -119,6 +120,12 @@ func WarnDeprecated(ctx context.Context, name, message string, fields map[string
return
}
}
+ for _, seenWarning := range seenWarnings {
+ if seenWarning == name {
+ return
+ }
+ }
+ seenWarnings = append(seenWarnings, name)
if fields == nil {
fields = map[string]any{}
}
diff --git a/pkg/outputter.go b/pkg/outputter.go
index 75df24f6..ca3fe9f1 100644
--- a/pkg/outputter.go
+++ b/pkg/outputter.go
@@ -326,6 +326,7 @@ func (m *Outputter) Generate(ctx context.Context, iface *Interface) error {
if err := parseConfigTemplates(ctx, interfaceConfig, iface); err != nil {
return fmt.Errorf("failed to parse config template: %w", err)
}
+ interfaceConfig.LogDeprecatedConfig(ctx)
g := GeneratorConfig{
Boilerplate: m.boilerplate,
From 9d2a002e19d41545580989282df0247626e131a2 Mon Sep 17 00:00:00 2001
From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com>
Date: Mon, 13 Jan 2025 23:10:15 -0600
Subject: [PATCH 4/7] Add deprecation for `structname`.
Resolves #844.
---
docs/configuration.md | 1 +
docs/deprecations.md | 17 ++++++++++++++++-
pkg/config/config.go | 8 ++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/docs/configuration.md b/docs/configuration.md
index aff32fa3..29bb883b 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -83,6 +83,7 @@ Parameter Descriptions
| `print` | :fontawesome-solid-x: | `#!yaml false` | Use `print: True` to have the resulting code printed out instead of written to disk. |
| [`recursive`](features.md#recursive-package-discovery) | :fontawesome-solid-x: | `#!yaml false` | When set to `true` on a particular package, mockery will recursively search for all sub-packages and inject those packages into the config map. |
| [`replace-type`](features.md#replace-types) | :fontawesome-solid-x: | `#!yaml null` | Replaces aliases, packages and/or types during generation. |
+| `resolve-type-alias` | :fontawesome-solid-x: | `#!yaml False` | Set to `True` if you would like mockery to resolve type aliases to their underlying type. In most cases, you do not want to resolve type aliases as it can break references to internal/private names. |
| `tags` | :fontawesome-solid-x: | `#!yaml ""` | A space-separated list of additional build tags to load packages. |
| [`with-expecter`](features.md#expecter-structs) | :fontawesome-solid-x: | `#!yaml true` | Use `with-expecter: True` to generate `EXPECT()` methods for your mocks. This is the preferred way to set up your mocks. |
diff --git a/docs/deprecations.md b/docs/deprecations.md
index edde9bb3..5cdac9f4 100644
--- a/docs/deprecations.md
+++ b/docs/deprecations.md
@@ -107,6 +107,7 @@ The `--quiet` parameter is superseded by `--log-level=""`. It will be removed in
`disable-version-string`
-----------------------
+
!!! tip ""
To resolve this warning:
@@ -115,4 +116,18 @@ The `--quiet` parameter is superseded by `--log-level=""`. It will be removed in
disable-version-string: True
```
-Mockery will no longer print the version of mockery used as a comment in the mock files.
\ No newline at end of file
+Mockery will no longer print the version of mockery used as a comment in the mock files.
+
+`structname`
+------------
+
+!!! tip ""
+
+ To resolve this warning:
+
+ ```yaml title=".mockery.yaml"
+ structname: ""
+ mockname: "NameOfMock"
+ ```
+
+If you're receiving this warning, you are likely not using the `packages` config feature anyway. It should be noted that `structname` will not be a config option in v3. Receipt of this warning means you need to upgrade to use the `packages` config feature.
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 3378e061..5f367030 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -861,4 +861,12 @@ func (c *Config) LogDeprecatedConfig(ctx context.Context) {
nil,
)
}
+ if c.StructName != "" {
+ logging.WarnDeprecated(
+ ctx,
+ "structname",
+ "structname will be removed as a parameter in v3",
+ nil,
+ )
+ }
}
From 564fbc4723aca9ff6c6427b8eeadd3cb3011dcc2 Mon Sep 17 00:00:00 2001
From: LandonTClipp <11232769+LandonTClipp@users.noreply.github.com>
Date: Tue, 14 Jan 2025 00:04:08 -0600
Subject: [PATCH 5/7] Simplify the log messages.
---
cmd/mockery.go | 2 +-
docs/configuration.md | 17 +++++++++--------
docs/stylesheets/extra.css | 14 ++++++++++++++
mkdocs.yml | 10 +++++++---
mockery-tools.env | 2 +-
pkg/config/config.go | 5 -----
.../mock_Interface2WithResolvedAlias_test.go | 2 +-
.../mock_Interface2WithUnresolvedAlias_test.go | 2 +-
pkg/generator.go | 6 +-----
pkg/logging/logging.go | 16 ++++++++++++++--
10 files changed, 49 insertions(+), 27 deletions(-)
diff --git a/cmd/mockery.go b/cmd/mockery.go
index ede49443..f9cb2e15 100644
--- a/cmd/mockery.go
+++ b/cmd/mockery.go
@@ -198,6 +198,7 @@ func (r *RootApp) Run() error {
}
logging.DisableDeprecationWarnings = r.Config.DisableDeprecationWarnings
logging.DisabledDeprecationWarnings = r.Config.DisabledDeprecationWarnings
+ defer logging.LogDeprecationWarnings()
log = log.With().Bool(logging.LogKeyDryRun, r.Config.DryRun).Logger()
log.Info().Msgf("Starting mockery")
@@ -233,7 +234,6 @@ func (r *RootApp) Run() error {
if r.Config.Packages == nil {
logging.WarnDeprecated(
- ctx,
"packages",
"use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
map[string]any{
diff --git a/docs/configuration.md b/docs/configuration.md
index 29bb883b..d43d427b 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -64,10 +64,10 @@ Parameter Descriptions
| `config` | :fontawesome-solid-x: | `#!yaml ""` | Set the location of the mockery config file. |
| `dir` | :fontawesome-solid-check: | `#!yaml "mocks/{{.PackagePath}}"` | The directory where the mock file will be outputted to. |
| `disable-config-search` | :fontawesome-solid-x: | `#!yaml false` | Disable searching for configuration files |
-| `disable-deprecation-warnings` | :fontawesome-solid-x: | `#!yaml false` | Disable all warnings for deprecated behavior. |
+| `disable-deprecation-warnings` | :fontawesome-solid-x: | `#!yaml false` | Disable all warnings for deprecated behavior. |
| `disabled-deprecation-warnings` | :fontawesome-solid-x: | `#!yaml []` | A list of strings that will selectively disable certain deprecation warnings. The name of each warning is given in the `deprecation-name` attribute of the log message. |
| `disable-func-mocks` | :fontawesome-solid-x: | `#!yaml false` | Disable generation of function mocks. |
-| `disable-version-string` | :fontawesome-solid-x: | `#!yaml false` | Disable the version string in the generated mock files. |
+| `disable-version-string` [:fontawesome-solid-triangle-exclamation:{ .deprecation }](deprecations.md#disable-version-string "Deprecated") | :fontawesome-solid-x: | `#!yaml false` | Disable the version string in the generated mock files. |
| `dry-run` | :fontawesome-solid-x: | `#!yaml false` | Print the actions that would be taken, but don't perform the actions. |
| `exclude` | :fontawesome-solid-x: | `#!yaml []` | Specify subpackages to exclude when using `#!yaml recursive: True` |
| `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. |
@@ -75,6 +75,7 @@ Parameter Descriptions
| `include-auto-generated` | :fontawesome-solid-x: | `#!yaml true` | Set to `#!yaml false` if you need mockery to skip auto-generated files during its recursive package discovery. When set to `#!yaml true`, mockery includes auto-generated files when determining if a particular directory is an importable package. |
| `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`. |
| `inpackage` | :fontawesome-solid-x: | `#!yaml false` | When generating mocks alongside the original interfaces, you must specify `inpackage: True` to inform mockery that the mock is being placed in the same package as the original interface. |
+| `issue-845-fix` [:fontawesome-solid-triangle-exclamation:{ .deprecation }](deprecations.md#issue-845-fix "Deprecated") | :fontawesome-solid-x: | `#!yaml false` | This fixes a configuration consistency issue found in [issue 845](https://github.com/vektra/mockery/issues/845). |
| `log-level` | :fontawesome-solid-x: | `#!yaml "info"` | Set the level of the logger |
| `mock-build-tags` | :fontawesome-solid-x: | `#!yaml ""` | Set the build tags of the generated mocks. Read more about the [format](https://pkg.go.dev/cmd/go#hdr-Build_constraints). |
| `mockname` | :fontawesome-solid-check: | `#!yaml "Mock{{.InterfaceName}}"` | The name of the generated mock. |
@@ -83,9 +84,9 @@ Parameter Descriptions
| `print` | :fontawesome-solid-x: | `#!yaml false` | Use `print: True` to have the resulting code printed out instead of written to disk. |
| [`recursive`](features.md#recursive-package-discovery) | :fontawesome-solid-x: | `#!yaml false` | When set to `true` on a particular package, mockery will recursively search for all sub-packages and inject those packages into the config map. |
| [`replace-type`](features.md#replace-types) | :fontawesome-solid-x: | `#!yaml null` | Replaces aliases, packages and/or types during generation. |
-| `resolve-type-alias` | :fontawesome-solid-x: | `#!yaml False` | Set to `True` if you would like mockery to resolve type aliases to their underlying type. In most cases, you do not want to resolve type aliases as it can break references to internal/private names. |
+| `resolve-type-alias` [:fontawesome-solid-triangle-exclamation:{ .deprecation }](deprecations.md#resolve-type-alias "Deprecated") | :fontawesome-solid-x: | `#!yaml False` | Set to `True` if you would like mockery to resolve type aliases to their underlying type. In most cases, you do not want to resolve type aliases as it can break references to internal/private names. |
| `tags` | :fontawesome-solid-x: | `#!yaml ""` | A space-separated list of additional build tags to load packages. |
-| [`with-expecter`](features.md#expecter-structs) | :fontawesome-solid-x: | `#!yaml true` | Use `with-expecter: True` to generate `EXPECT()` methods for your mocks. This is the preferred way to set up your mocks. |
+| [`with-expecter`](features.md#expecter-structs) [:fontawesome-solid-triangle-exclamation:{ .deprecation }](deprecations.md#with-expecter "Deprecated") | :fontawesome-solid-x: | `#!yaml true` | Use `with-expecter: True` to generate `EXPECT()` methods for your mocks. This is the preferred way to set up your mocks. |
Layouts
-------
@@ -205,10 +206,10 @@ Variables that are marked as being templated are capable of using mockery-provid
| InterfaceDirRelative | The directory path of the original interface being mocked, relative to the current working directory. If the path cannot be made relative to the current working directory, this variable will be set equal to `PackagePath` |
| InterfaceFile | The file path of the original interface being mocked. **NOTE:** This option will only write one mock implementation to the output file. If multiple mocks are defined in your original file, only one mock will be written to the output. |
| InterfaceName | The name of the original interface being mocked |
-| InterfaceNameCamel | Converts a string `interface_name` to `InterfaceName`.
DEPRECATED: use `{{ .InterfaceName | camelcase }}` instead |
-| InterfaceNameLowerCamel | Converts `InterfaceName` to `interfaceName` .
DEPRECATED: use `{{ .InterfaceName | camelcase | firstLower }}` instead |
-| InterfaceNameSnake | Converts `InterfaceName` to `interface_name` .
DEPRECATED: use `{{ .InterfaceName | snakecase }}` instead |
-| InterfaceNameLower | Converts `InterfaceName` to `interfacename` .
DEPRECATED: use `{{ .InterfaceName | lower }}` instead |
+| InterfaceNameCamel | Converts a string `interface_name` to `InterfaceName`.