Skip to content

Commit 98c811d

Browse files
build(deps): bump github.com/firefart/nonamedreturns from 1.0.1 to 1.0.2 (#2929)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent ae2a968 commit 98c811d

File tree

9 files changed

+291
-10
lines changed

9 files changed

+291
-10
lines changed

.golangci.reference.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,11 @@ linters-settings:
11541154
# Default: false
11551155
require-specific: true
11561156

1157+
nonamedreturns:
1158+
# Do not complain about named error, if it is assigned inside defer.
1159+
# Default: false
1160+
allow-error-in-defer: true
1161+
11571162
paralleltest:
11581163
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
11591164
# Default: false

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/denis-tingaikin/go-header v0.4.3
2525
github.com/esimonov/ifshort v1.0.4
2626
github.com/fatih/color v1.13.0
27-
github.com/firefart/nonamedreturns v1.0.1
27+
github.com/firefart/nonamedreturns v1.0.2
2828
github.com/fzipp/gocyclo v0.5.1
2929
github.com/go-critic/go-critic v0.6.3
3030
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ type LintersSettings struct {
158158
NilNil NilNilSettings
159159
Nlreturn NlreturnSettings
160160
NoLintLint NoLintLintSettings
161+
NoNamedReturns NoNamedReturnsSettings
161162
ParallelTest ParallelTestSettings
162163
Prealloc PreallocSettings
163164
Predeclared PredeclaredSettings
@@ -484,6 +485,9 @@ type NoLintLintSettings struct {
484485
AllowUnused bool `mapstructure:"allow-unused"`
485486
}
486487

488+
type NoNamedReturnsSettings struct {
489+
AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"`
490+
}
487491
type ParallelTestSettings struct {
488492
IgnoreMissing bool `mapstructure:"ignore-missing"`
489493
}

pkg/golinters/nonamedreturns.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ import (
44
"github.com/firefart/nonamedreturns/analyzer"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
89
)
910

10-
func NewNoNamedReturns() *goanalysis.Linter {
11+
func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Linter {
12+
a := analyzer.Analyzer
13+
14+
var cfg map[string]map[string]interface{}
15+
if settings != nil {
16+
cfg = map[string]map[string]interface{}{
17+
a.Name: {
18+
analyzer.FlagAllowErrorInDefer: settings.AllowErrorInDefer,
19+
},
20+
}
21+
}
22+
1123
return goanalysis.NewLinter(
12-
"nonamedreturns",
13-
"Reports all named returns",
14-
[]*analysis.Analyzer{analyzer.Analyzer},
15-
nil,
24+
a.Name,
25+
a.Doc,
26+
[]*analysis.Analyzer{a},
27+
cfg,
1628
).WithLoadMode(goanalysis.LoadModeSyntax)
1729
}

pkg/lint/lintersdb/manager.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
147147
nilNilCfg *config.NilNilSettings
148148
nlreturnCfg *config.NlreturnSettings
149149
noLintLintCfg *config.NoLintLintSettings
150+
noNamedReturnsCfg *config.NoNamedReturnsSettings
150151
parallelTestCfg *config.ParallelTestSettings
151152
preallocCfg *config.PreallocSettings
152153
predeclaredCfg *config.PredeclaredSettings
@@ -216,6 +217,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
216217
nilNilCfg = &m.cfg.LintersSettings.NilNil
217218
nlreturnCfg = &m.cfg.LintersSettings.Nlreturn
218219
noLintLintCfg = &m.cfg.LintersSettings.NoLintLint
220+
noNamedReturnsCfg = &m.cfg.LintersSettings.NoNamedReturns
219221
preallocCfg = &m.cfg.LintersSettings.Prealloc
220222
parallelTestCfg = &m.cfg.LintersSettings.ParallelTest
221223
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
@@ -623,7 +625,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
623625
WithURL("https://github.com/sonatard/noctx").
624626
WithNoopFallback(m.cfg),
625627

626-
linter.NewConfig(golinters.NewNoNamedReturns()).
628+
linter.NewConfig(golinters.NewNoNamedReturns(noNamedReturnsCfg)).
627629
WithSince("v1.46.0").
628630
WithPresets(linter.PresetStyle).
629631
WithURL("https://github.com/firefart/nonamedreturns"),
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
nonamedreturns:
3+
allow-error-in-defer: true

test/testdata/nonamedreturns.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//args: -Enonamedreturns
1+
// args: -Enonamedreturns
22
package testdata
33

44
import "fmt"
@@ -24,6 +24,17 @@ var e = func() (err error) { // ERROR `named return "err" with type "error" foun
2424
return
2525
}
2626

27+
var e2 = func() (_ error) {
28+
return
29+
}
30+
31+
func deferWithError() (err error) { // ERROR `named return "err" with type "error" found`
32+
defer func() {
33+
err = nil // use flag to allow this
34+
}()
35+
return
36+
}
37+
2738
var (
2839
f = func() {
2940
return
@@ -37,6 +48,10 @@ var (
3748
err = nil
3849
return
3950
}
51+
52+
h2 = func() (_ error) {
53+
return
54+
}
4055
)
4156

4257
// this should not match as the implementation does not need named parameters (see below)
@@ -50,11 +65,24 @@ func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // ERROR
5065
return 0, nil
5166
}
5267

68+
func funcDefintionImpl3(arg1, arg2 interface{}) (num int, _ error) { // ERROR `named return "num" with type "int" found`
69+
return 0, nil
70+
}
71+
72+
func funcDefintionImpl4(arg1, arg2 interface{}) (_ int, _ error) {
73+
return 0, nil
74+
}
75+
5376
var funcVar = func() (msg string) { // ERROR `named return "msg" with type "string" found`
5477
msg = "c"
5578
return msg
5679
}
5780

81+
var funcVar2 = func() (_ string) {
82+
msg := "c"
83+
return msg
84+
}
85+
5886
func test() {
5987
a := funcVar()
6088
_ = a
@@ -92,3 +120,5 @@ func myLog(format string, args ...interface{}) {
92120
type obj struct{}
93121

94122
func (o *obj) func1() (err error) { return nil } // ERROR `named return "err" with type "error" found`
123+
124+
func (o *obj) func2() (_ error) { return nil }

0 commit comments

Comments
 (0)