diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 8f337f182f2a..5e14e144fcce 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1159,6 +1159,10 @@ linters-settings: require-specific: true nonamedreturns: + # Report named error if it is assigned inside defer. + # Default: false + report-error-in-defer: true + # DEPRECATED use report-error-in-defer instead. # Do not complain about named error, if it is assigned inside defer. # Default: false allow-error-in-defer: true diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 3b5ceddf32de..43be7f6d6f68 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -486,7 +486,8 @@ type NoLintLintSettings struct { } type NoNamedReturnsSettings struct { - AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"` + AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"` // Deprecated: use ReportErrorInDefer instead. + ReportErrorInDefer bool `mapstructure:"report-error-in-defer"` } type ParallelTestSettings struct { IgnoreMissing bool `mapstructure:"ignore-missing"` diff --git a/pkg/golinters/nonamedreturns.go b/pkg/golinters/nonamedreturns.go index a8166f81672b..6cf608ee0286 100644 --- a/pkg/golinters/nonamedreturns.go +++ b/pkg/golinters/nonamedreturns.go @@ -15,7 +15,7 @@ func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Lint if settings != nil { cfg = map[string]map[string]interface{}{ a.Name: { - analyzer.FlagAllowErrorInDefer: settings.AllowErrorInDefer, + analyzer.FlagReportErrorInDefer: settings.ReportErrorInDefer || settings.AllowErrorInDefer, }, } } @@ -25,5 +25,5 @@ func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Lint a.Doc, []*analysis.Analyzer{a}, cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + ).WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 58db15a6075c..e6c069b7f56f 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -627,6 +627,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { linter.NewConfig(golinters.NewNoNamedReturns(noNamedReturnsCfg)). WithSince("v1.46.0"). + WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). WithURL("https://github.com/firefart/nonamedreturns"),