From 0f55ecb59bba3d59affb8261d21d8f3e0cbf335b Mon Sep 17 00:00:00 2001 From: Landon Clipp <11232769+LandonTClipp@users.noreply.github.com> Date: Tue, 14 Jan 2025 00:17:05 -0600 Subject: [PATCH] Add enhanced deprecation logging support. (#894) * Add enhanced deprecation logging support. This commit adds the ability to silence particular deprecation messages. It also resolved #893. Add dep warn for `disable-version-string` Resolves #872. Add deprecation for `structname`. Resolves #844. --- .golangci.yml | 1 - cmd/mockery.go | 21 ++-- docs/configuration.md | 24 ++-- docs/deprecations.md | 48 +++++++- docs/stylesheets/extra.css | 14 +++ mkdocs.yml | 10 +- mockery-tools.env | 2 +- pkg/config/config.go | 116 ++++++++++++------ .../mock_Interface2WithResolvedAlias_test.go | 2 +- ...mock_Interface2WithUnresolvedAlias_test.go | 2 +- pkg/generator.go | 9 +- pkg/logging/logging.go | 46 ++++++- pkg/outputter.go | 1 + 13 files changed, 212 insertions(+), 84 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1f3426534..66c67f52a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,7 +12,6 @@ linters: - ineffassign - staticcheck - typecheck - - contextcheck - durationcheck - copyloopvar - gocheckcompilerdirectives diff --git a/cmd/mockery.go b/cmd/mockery.go index 4cccae4ae..f9cb2e154 100644 --- a/cmd/mockery.go +++ b/cmd/mockery.go @@ -196,6 +196,10 @@ 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 + defer logging.LogDeprecationWarnings() + log = log.With().Bool(logging.LogKeyDryRun, r.Config.DryRun).Logger() log.Info().Msgf("Starting mockery") log.Info().Msgf("Using config: %s", r.Config.Config) @@ -228,12 +232,13 @@ func (r *RootApp) Run() error { boilerplate = string(data) } - if !r.Config.WithExpecter { + if r.Config.Packages == nil { logging.WarnDeprecated( - ctx, - "with-expecter will be permanently set to True in v3", + "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("/deprecations/#with-expecter"), + "url": logging.DocsURL("/features/#packages-configuration"), + "migration": logging.DocsURL("/migrating_to_packages/"), }, ) } @@ -309,14 +314,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, - "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/docs/configuration.md b/docs/configuration.md index 189081333..d43d427be 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,8 +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. | +| `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. | @@ -73,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. | @@ -81,8 +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-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 ------- @@ -130,7 +134,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 +190,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,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`.
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 | | Mock | A string that is `Mock` if the interface is exported, or `mock` if it is not exported. Useful when setting the name of your mock to something like:
`#!yaml mockname: "{{.Mock}}{{.InterfaceName}}"`
This way, the mock name will retain the exported-ness of the original interface. | | MockName | The name of the mock that will be generated. Note that this is simply the `mockname` configuration variable | | PackageName | The name of the package from the original interface | @@ -258,7 +262,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 3c7b699b2..5cdac9f47 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,50 @@ 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. + +`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. + +`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/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index f693be070..2596bbffb 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -13,3 +13,17 @@ .md-grid { max-width: none; } + +.deprecated { + color: var(--md-code-hl-number-color); + font-weight: bold; +} + +a .deprecation { + transition: color 125ms; + color: var(--md-code-hl-number-color); +} + +.deprecation:hover { + color: darkred; +} diff --git a/mkdocs.yml b/mkdocs.yml index e5f71212d..88cd30c76 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -31,6 +31,7 @@ theme: - content.code.copy - content.action.edit - content.action.view + - content.tooltips - navigation.indexes - navigation.sections - navigation.tracking @@ -39,6 +40,9 @@ markdown_extensions: - admonition - attr_list - md_in_html + - pymdownx.caret + - pymdownx.mark + - pymdownx.tilde - pymdownx.emoji: emoji_index: !!python/name:material.extensions.emoji.twemoji emoji_generator: !!python/name:material.extensions.emoji.to_svg @@ -50,10 +54,10 @@ markdown_extensions: - pymdownx.magiclink - pymdownx.superfences - pymdownx.tabbed: - alternate_style: true + alternate_style: true - toc: permalink: true - + nav: - Home: index.md @@ -63,7 +67,7 @@ nav: - Running: running.md - Examples: examples.md - Features: features.md - - Notes: + - Notes: - FAQ: notes.md - Changelog: changelog.md - Migrating to Packages: migrating_to_packages.md diff --git a/mockery-tools.env b/mockery-tools.env index 985077a71..90c070490 100644 --- a/mockery-tools.env +++ b/mockery-tools.env @@ -1 +1 @@ -VERSION=v2.50.4 +VERSION=v2.51.0 diff --git a/pkg/config/config.go b/pkg/config/config.go index 72b231e34..4f11d0411 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"` @@ -825,3 +827,41 @@ 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( + "with-expecter", + "with-expecter will be permanently set to True in v3", + nil, + ) + } + if c.Quiet { + logging.WarnDeprecated( + "quiet", + "The --quiet parameter will be removed in v3. Use --log-level=\"\" instead", + nil, + ) + } + if c.ResolveTypeAlias { + logging.WarnDeprecated( + "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( + "disable-version-string", + "disable-version-string will be permanently set to True in v3", + nil, + ) + } + if c.StructName != "" { + logging.WarnDeprecated( + "structname", + "structname will be removed as a parameter in v3", + nil, + ) + } +} diff --git a/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go b/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go index 80cdaabe1..151740171 100644 --- a/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go +++ b/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go @@ -51,7 +51,7 @@ func (_c *Interface2WithResolvedAlias_F_Call) Return() *Interface2WithResolvedAl } func (_c *Interface2WithResolvedAlias_F_Call) RunAndReturn(run func(int, subpkg.S, subpkg.S)) *Interface2WithResolvedAlias_F_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go b/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go index 68b64cf07..cfce9f177 100644 --- a/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go +++ b/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go @@ -52,7 +52,7 @@ func (_c *Interface2WithUnresolvedAlias_F_Call) Return() *Interface2WithUnresolv } func (_c *Interface2WithUnresolvedAlias_F_Call) RunAndReturn(run func(type_alias.Type, type_alias.S, subpkg.S)) *Interface2WithUnresolvedAlias_F_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/pkg/generator.go b/pkg/generator.go index bcda68cb5..7108dc6c5 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -425,7 +425,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"), @@ -540,13 +540,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 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 ca266758a..071f37e96 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -28,8 +28,13 @@ const ( defaultSemVer = "v0.0.0-dev" ) -// SemVer is the version of mockery at build time. -var SemVer = "" +var ( + SemVer = "" + DisableDeprecationWarnings bool + DisabledDeprecationWarnings []string + seenWarnings []string + deferredCalls []func() +) var ErrPkgNotExist = errors.New("package does not exist") @@ -44,6 +49,12 @@ func GetSemverInfo() string { return defaultSemVer } +func LogDeprecationWarnings() { + for _, warn := range deferredCalls { + warn() + } +} + func getMinorSemver(semver string) string { split := strings.Split(semver, ".") return strings.Join(split[0:2], ".") @@ -86,7 +97,6 @@ func GetLogger(levelStr string) (zerolog.Logger, error) { With(). Str("version", GetSemverInfo()). Logger() - return log, nil } @@ -108,6 +118,32 @@ 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) { - Warn(ctx, "DEPRECATION", message, fields) +func WarnDeprecated(name, message string, fields map[string]any) { + log, _ := GetLogger("warn") + ctx := log.WithContext(context.Background()) + if DisableDeprecationWarnings { + return + } + for _, disabledWarning := range DisabledDeprecationWarnings { + if disabledWarning == name { + return + } + } + for _, seenWarning := range seenWarnings { + if seenWarning == name { + return + } + } + seenWarnings = append(seenWarnings, name) + if fields == nil { + fields = map[string]any{} + } + fields["deprecation-name"] = name + if _, ok := fields["url"]; !ok { + fields["url"] = DocsURL(fmt.Sprintf("/deprecations/#%s", name)) + } + + deferredCalls = append(deferredCalls, func() { + Warn(ctx, "DEPRECATION", message, fields) + }) } diff --git a/pkg/outputter.go b/pkg/outputter.go index 75df24f6a..ca3fe9f1c 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,