Skip to content

Commit 1edb1ca

Browse files
committed
add more testcases
1 parent 7814ad9 commit 1edb1ca

File tree

7 files changed

+107
-38
lines changed

7 files changed

+107
-38
lines changed

.golangci.example.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ linters-settings:
790790
- lostcancel
791791
- nilfunc
792792
- nilness
793-
- nonamedreturnlint
793+
- nonamedreturns
794794
- printf
795795
- reflectvaluecompare
796796
- shadow
@@ -834,7 +834,7 @@ linters-settings:
834834
- lostcancel
835835
- nilfunc
836836
- nilness
837-
- nonamedreturnlint
837+
- nonamedreturns
838838
- printf
839839
- reflectvaluecompare
840840
- shadow

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/denis-tingaikin/go-header v0.4.3
2424
github.com/esimonov/ifshort v1.0.4
2525
github.com/fatih/color v1.13.0
26-
github.com/firefart/nonamedreturnlint v1.0.0
26+
github.com/firefart/nonamedreturns v1.0.0
2727
github.com/fzipp/gocyclo v0.5.0
2828
github.com/go-critic/go-critic v0.6.2
2929
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
@@ -162,7 +162,7 @@ require (
162162
github.com/yusufpapurcu/wmi v1.2.2 // indirect
163163
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
164164
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
165-
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
165+
golang.org/x/sys v0.0.0-20220403020550-483a9cbc67c0 // indirect
166166
golang.org/x/text v0.3.7 // indirect
167167
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
168168
google.golang.org/protobuf v1.27.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/nonamedreturnlint.go renamed to pkg/golinters/nonamedreturns.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package golinters
22

33
import (
4-
"github.com/firefart/nonamedreturnlint/analyzer"
4+
"github.com/firefart/nonamedreturns/analyzer"
55
"golang.org/x/tools/go/analysis"
66

77
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
88
)
99

10-
func NewNoNamedReturnLint() *goanalysis.Linter {
10+
func NewNoNamedReturns() *goanalysis.Linter {
1111
return goanalysis.NewLinter(
12-
"nonamedreturnlint",
12+
"nonamedreturns",
1313
"Reports all named returns",
1414
[]*analysis.Analyzer{analyzer.Analyzer},
1515
nil,

pkg/lint/lintersdb/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
527527
WithURL("https://github.com/sonatard/noctx").
528528
WithNoopFallback(m.cfg),
529529

530-
linter.NewConfig(golinters.NewNoNamedReturnLint()).
530+
linter.NewConfig(golinters.NewNoNamedReturns()).
531531
WithSince("v1.46.0").
532532
WithPresets(linter.PresetStyle).
533-
WithURL("https://github.com/FireFart/nonamedreturnlint"),
533+
WithURL("https://github.com/firefart/nonamedreturns"),
534534

535535
linter.NewConfig(golinters.NewParallelTest()).
536536
WithSince("v1.33.0").

test/testdata/nonamedreturnlint.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/testdata/nonamedreturns.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//args: -Enonamedreturns
2+
package testdata
3+
4+
import "fmt"
5+
6+
type asdf struct {
7+
test string
8+
}
9+
10+
func noParams() {
11+
return
12+
}
13+
14+
var c = func() {
15+
return
16+
}
17+
18+
var d = func() error {
19+
return nil
20+
}
21+
22+
var e = func() (err error) { // ERROR `named return "err" with type "error" found`
23+
err = nil
24+
return
25+
}
26+
27+
var (
28+
f = func() {
29+
return
30+
}
31+
32+
g = func() error {
33+
return nil
34+
}
35+
36+
h = func() (err error) { // ERROR `named return "err" with type "error" found`
37+
err = nil
38+
return
39+
}
40+
)
41+
42+
// this should not match as the implementation does not need named parameters (see below)
43+
type funcDefintion func(arg1, arg2 interface{}) (num int, err error)
44+
45+
func funcDefintionImpl(arg1, arg2 interface{}) (int, error) {
46+
return 0, nil
47+
}
48+
49+
func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // ERROR `named return "num" with type "int" found`
50+
return 0, nil
51+
}
52+
53+
var funcVar = func() (msg string) { // ERROR `named return "msg" with type "string" found`
54+
msg = "c"
55+
return msg
56+
}
57+
58+
func test() {
59+
a := funcVar()
60+
_ = a
61+
62+
var function funcDefintion
63+
function = funcDefintionImpl
64+
i, err := function("", "")
65+
_ = i
66+
_ = err
67+
function = funcDefintionImpl2
68+
i, err = function("", "")
69+
_ = i
70+
_ = err
71+
}
72+
73+
func good(i string) string {
74+
return i
75+
}
76+
77+
func bad(i string, a, b int) (ret1 string, ret2 interface{}, ret3, ret4 int, ret5 asdf) { // ERROR `named return "ret1" with type "string" found`
78+
x := "dummy"
79+
return fmt.Sprintf("%s", x), nil, 1, 2, asdf{}
80+
}
81+
82+
func bad2() (msg string, err error) { // ERROR `named return "msg" with type "string" found`
83+
msg = ""
84+
err = nil
85+
return
86+
}
87+
88+
func myLog(format string, args ...interface{}) {
89+
return
90+
}
91+
92+
type obj struct{}
93+
94+
func (o *obj) func1() (err error) { return nil } // ERROR `named return "err" with type "error" found`

0 commit comments

Comments
 (0)