Skip to content

Commit d2f4668

Browse files
committed
review: update implementation
1 parent a026bd1 commit d2f4668

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

.golangci.reference.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,10 @@ linters-settings:
11591159
require-specific: true
11601160

11611161
nonamedreturns:
1162+
# Report named error if it is assigned inside defer.
1163+
# Default: false
1164+
report-error-in-defer: true
1165+
# DEPRECATED use report-error-in-defer instead.
11621166
# Do not complain about named error, if it is assigned inside defer.
11631167
# Default: false
11641168
allow-error-in-defer: true

pkg/config/linters_settings.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ type NoLintLintSettings struct {
486486
}
487487

488488
type NoNamedReturnsSettings struct {
489-
AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"`
489+
AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"` // Deprecated: use ReportErrorInDefer instead.
490+
ReportErrorInDefer bool `mapstructure:"report-error-in-defer"`
490491
}
491492
type ParallelTestSettings struct {
492493
IgnoreMissing bool `mapstructure:"ignore-missing"`

pkg/golinters/nonamedreturns.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Lint
1515
if settings != nil {
1616
cfg = map[string]map[string]interface{}{
1717
a.Name: {
18-
analyzer.FlagAllowErrorInDefer: settings.AllowErrorInDefer,
18+
analyzer.FlagReportErrorInDefer: settings.ReportErrorInDefer || settings.AllowErrorInDefer,
1919
},
2020
}
2121
}
@@ -25,5 +25,5 @@ func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Lint
2525
a.Doc,
2626
[]*analysis.Analyzer{a},
2727
cfg,
28-
).WithLoadMode(goanalysis.LoadModeSyntax)
28+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
2929
}

pkg/lint/lintersdb/manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
627627

628628
linter.NewConfig(golinters.NewNoNamedReturns(noNamedReturnsCfg)).
629629
WithSince("v1.46.0").
630+
WithLoadForGoAnalysis().
630631
WithPresets(linter.PresetStyle).
631632
WithURL("https://github.com/firefart/nonamedreturns"),
632633

0 commit comments

Comments
 (0)