build(deps): bump github.com/firefart/nonamedreturns from 1.0.2 to 1.0.4 (#2944)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
dependabot[bot] 2022-06-28 14:13:15 +02:00 committed by GitHub
parent 01f1a070a2
commit 023e1c4fdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 381 additions and 323 deletions

View File

@ -1159,9 +1159,9 @@ linters-settings:
require-specific: true
nonamedreturns:
# Do not complain about named error, if it is assigned inside defer.
# Report named error if it is assigned inside defer.
# Default: false
allow-error-in-defer: true
report-error-in-defer: true
paralleltest:
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.

4
go.mod
View File

@ -24,7 +24,7 @@ require (
github.com/denis-tingaikin/go-header v0.4.3
github.com/esimonov/ifshort v1.0.4
github.com/fatih/color v1.13.0
github.com/firefart/nonamedreturns v1.0.2
github.com/firefart/nonamedreturns v1.0.4
github.com/fzipp/gocyclo v0.6.0
github.com/go-critic/go-critic v0.6.3
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
@ -170,7 +170,7 @@ require (
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect

8
go.sum generated
View File

@ -157,8 +157,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/firefart/nonamedreturns v1.0.2 h1:TJ4bRW6KQaNo5t4JVQdjRAOAB7LTxDvkN16c05XtXaA=
github.com/firefart/nonamedreturns v1.0.2/go.mod h1:dLEDwtlLtW+0788N0RCymzvtvfanAFP8V1ZTkY0HwD8=
github.com/firefart/nonamedreturns v1.0.4 h1:abzI1p7mAEPYuR4A+VLKn4eNDOycjYo2phmY9sfv40Y=
github.com/firefart/nonamedreturns v1.0.4/go.mod h1:TDhe/tjI1BXo48CmYbUduTV7BdIga8MAO/xbKdcVsGI=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@ -958,8 +958,8 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJIkPFVM6oDtMFYmgws0=
golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

View File

@ -486,7 +486,7 @@ type NoLintLintSettings struct {
}
type NoNamedReturnsSettings struct {
AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"`
ReportErrorInDefer bool `mapstructure:"report-error-in-defer"`
}
type ParallelTestSettings struct {
IgnoreMissing bool `mapstructure:"ignore-missing"`

View File

@ -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,
},
}
}
@ -25,5 +25,5 @@ func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Lint
a.Doc,
[]*analysis.Analyzer{a},
cfg,
).WithLoadMode(goanalysis.LoadModeSyntax)
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}

View File

@ -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"),

View File

@ -1,3 +1,3 @@
linters-settings:
nonamedreturns:
allow-error-in-defer: true
report-error-in-defer: true

View File

@ -1,124 +1,281 @@
// args: -Enonamedreturns
package testdata
import "fmt"
import "errors"
type asdf struct {
test string
}
func noParams() {
return
}
var c = func() {
return
}
var d = func() error {
return nil
}
var e = func() (err error) { // ERROR `named return "err" with type "error" found`
err = nil
return
}
var e2 = func() (_ error) {
return
}
func deferWithError() (err error) { // ERROR `named return "err" with type "error" found`
func simple() (err error) {
defer func() {
err = nil // use flag to allow this
err = nil
}()
return
}
var (
f = func() {
return
}
g = func() error {
return nil
}
h = func() (err error) { // ERROR `named return "err" with type "error" found`
func twoReturnParams() (i int, err error) { // ERROR `named return "i" with type "int" found`
defer func() {
i = 0
err = nil
return
}
h2 = func() (_ error) {
return
}
)
// this should not match as the implementation does not need named parameters (see below)
type funcDefintion func(arg1, arg2 interface{}) (num int, err error)
func funcDefintionImpl(arg1, arg2 interface{}) (int, error) {
return 0, nil
}
func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // ERROR `named return "num" with type "int" found`
return 0, nil
}
func funcDefintionImpl3(arg1, arg2 interface{}) (num int, _ error) { // ERROR `named return "num" with type "int" found`
return 0, nil
}
func funcDefintionImpl4(arg1, arg2 interface{}) (_ int, _ error) {
return 0, nil
}
var funcVar = func() (msg string) { // ERROR `named return "msg" with type "string" found`
msg = "c"
return msg
}
var funcVar2 = func() (_ string) {
msg := "c"
return msg
}
func test() {
a := funcVar()
_ = a
var function funcDefintion
function = funcDefintionImpl
i, err := function("", "")
_ = i
_ = err
function = funcDefintionImpl2
i, err = function("", "")
_ = i
_ = err
}
func good(i string) string {
return i
}
func bad(i string, a, b int) (ret1 string, ret2 interface{}, ret3, ret4 int, ret5 asdf) { // ERROR `named return "ret1" with type "string" found`
x := "dummy"
return fmt.Sprintf("%s", x), nil, 1, 2, asdf{}
}
func bad2() (msg string, err error) { // ERROR `named return "msg" with type "string" found`
msg = ""
err = nil
}()
return
}
func myLog(format string, args ...interface{}) {
func allUnderscoresExceptError() (_ int, err error) {
defer func() {
err = nil
}()
return
}
type obj struct{}
func customName() (myName error) {
defer func() {
myName = nil
}()
return
}
func (o *obj) func1() (err error) { return nil } // ERROR `named return "err" with type "error" found`
func errorIsNoAssigned() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
_ = err
processError(err)
if err == nil {
}
switch err {
case nil:
default:
}
}()
return
}
func (o *obj) func2() (_ error) { return nil }
func shadowVariable() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
err := errors.New("xxx")
_ = err
}()
return
}
func shadowVariableButAssign() (err error) {
defer func() {
{
err := errors.New("xxx")
_ = err
}
err = nil
}()
return
}
func shadowVariable2() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
a, err := doSomething()
_ = a
_ = err
}()
return
}
type errorAlias = error
func errorAliasIsTheSame() (err errorAlias) {
defer func() {
err = nil
}()
return
}
type myError error // linter doesn't check underlying type (yet?)
func customTypeWithErrorUnderline() (err myError) { // ERROR `named return "err" with type "myError" found`
defer func() {
err = nil
}()
return
}
type myError2 interface{ error } // linter doesn't check interfaces
func customTypeWithTheSameInterface() (err myError2) { // ERROR `named return "err" with type "myError2" found`
defer func() {
err = nil
}()
return
}
var _ error = myError3{}
type myError3 struct{} // linter doesn't check interfaces
func (m myError3) Error() string { return "" }
func customTypeImplementingErrorInterface() (err myError3) { // ERROR `named return "err" with type "myError3" found`
defer func() {
err = struct{}{}
}()
return
}
func shadowErrorType() {
type error interface { // linter understands that this is not built-in error, even if it has the same name
Error() string
}
do := func() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
err = nil
}()
return
}
do()
}
func notTheLast() (err error, _ int) {
defer func() {
err = nil
}()
return
}
func twoErrorsCombined() (err1, err2 error) {
defer func() {
err1 = nil
err2 = nil
}()
return
}
func twoErrorsSeparated() (err1 error, err2 error) {
defer func() {
err1 = nil
err2 = nil
}()
return
}
func errorSlice() (err []error) { // ERROR `named return "err" with type "\[\]error" found`
defer func() {
err = nil
}()
return
}
func deferWithVariable() (err error) { // ERROR `named return "err" with type "error" found`
f := func() {
err = nil
}
defer f() // linter can't catch closure passed via variable (yet?)
return
}
func uberMultierr() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
multierrAppendInto(&err, nil) // linter doesn't allow it (yet?)
}()
return
}
func deferInDefer() (err error) {
defer func() {
defer func() {
err = nil
}()
}()
return
}
func twoDefers() (err error) {
defer func() {}()
defer func() {
err = nil
}()
return
}
func callFunction() (err error) {
defer func() {
_, err = doSomething()
}()
return
}
func callFunction2() (err error) {
defer func() {
var a int
a, err = doSomething()
_ = a
}()
return
}
func deepInside() (err error) {
if true {
switch true {
case false:
for i := 0; i < 10; i++ {
go func() {
select {
default:
defer func() {
if true {
switch true {
case false:
for j := 0; j < 10; j++ {
go func() {
select {
default:
err = nil
}
}()
}
}
}
}()
}
}()
}
}
}
return
}
var goodFuncLiteral = func() (err error) {
defer func() {
err = nil
}()
return
}
var badFuncLiteral = func() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
_ = err
}()
return
}
func funcLiteralInsideFunc() error {
do := func() (err error) {
defer func() {
err = nil
}()
return
}
return do()
}
type x struct{}
func (x) goodMethod() (err error) {
defer func() {
err = nil
}()
return
}
func (x) badMethod() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
_ = err
}()
return
}
func processError(error) {}
func doSomething() (int, error) { return 10, nil }
func multierrAppendInto(*error, error) bool { return false } // https://pkg.go.dev/go.uber.org/multierr#AppendInto

View File

@ -2,224 +2,124 @@
// config_path: testdata/configs/nonamedreturns.yml
package testdata
func simple() (err error) {
import "fmt"
type asdf struct {
test string
}
func noParams() {
return
}
var c = func() {
return
}
var d = func() error {
return nil
}
var e = func() (err error) { // ERROR `named return "err" with type "error" found`
err = nil
return
}
var e2 = func() (_ error) {
return
}
func deferWithError() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
err = nil
err = nil // use flag to allow this
}()
return
}
func twoReturnParams() (i int, err error) { // ERROR `named return "i" with type "int" found`
defer func() {
i = 0
err = nil
}()
return
}
func allUnderscoresExceptError() (_ int, err error) {
defer func() {
err = nil
}()
return
}
func customName() (myName error) {
defer func() {
myName = nil
}()
return
}
func errorIsNoAssigned() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
_ = err
processError(err)
if err == nil {
}
switch err {
case nil:
default:
}
}()
return
}
func shadowVariable() (err error) {
defer func() {
err := 123 // linter doesn't understand that this is different variable (even if different type) (yet?)
_ = err
}()
return
}
func shadowVariable2() (err error) {
defer func() {
a, err := doSomething() // linter doesn't understand that this is different variable (yet?)
_ = a
_ = err
}()
return
}
type myError = error // linter doesn't understand that this is the same type (yet?)
func customType() (err myError) { // ERROR `named return "err" with type "myError" found`
defer func() {
err = nil
}()
return
}
func notTheLast() (err error, _ int) {
defer func() {
err = nil
}()
return
}
func twoErrorsCombined() (err1, err2 error) {
defer func() {
err1 = nil
err2 = nil
}()
return
}
func twoErrorsSeparated() (err1 error, err2 error) {
defer func() {
err1 = nil
err2 = nil
}()
return
}
func errorSlice() (err []error) { // ERROR `named return "err" with type "\[\]error" found`
defer func() {
err = nil
}()
return
}
func deferWithVariable() (err error) { // ERROR `named return "err" with type "error" found`
f := func() {
err = nil
}
defer f() // linter can't catch closure passed via variable (yet?)
return
}
func uberMultierr() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
multierrAppendInto(&err, nil) // linter doesn't allow it (yet?)
}()
return
}
func deferInDefer() (err error) {
defer func() {
defer func() {
err = nil
}()
}()
return
}
func twoDefers() (err error) {
defer func() {}()
defer func() {
err = nil
}()
return
}
func callFunction() (err error) {
defer func() {
_, err = doSomething()
}()
return
}
func callFunction2() (err error) {
defer func() {
var a int
a, err = doSomething()
_ = a
}()
return
}
func deepInside() (err error) {
if true {
switch true {
case false:
for i := 0; i < 10; i++ {
go func() {
select {
default:
defer func() {
if true {
switch true {
case false:
for j := 0; j < 10; j++ {
go func() {
select {
default:
err = nil
}
}()
}
}
}
}()
}
}()
}
}
}
return
}
var goodFuncLiteral = func() (err error) {
defer func() {
err = nil
}()
return
}
var badFuncLiteral = func() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
_ = err
}()
return
}
func funcLiteralInsideFunc() error {
do := func() (err error) {
defer func() {
err = nil
}()
var (
f = func() {
return
}
return do()
}
type x struct{}
g = func() error {
return nil
}
func (x) goodMethod() (err error) {
defer func() {
h = func() (err error) { // ERROR `named return "err" with type "error" found`
err = nil
}()
return
}
h2 = func() (_ error) {
return
}
)
// this should not match as the implementation does not need named parameters (see below)
type funcDefintion func(arg1, arg2 interface{}) (num int, err error)
func funcDefintionImpl(arg1, arg2 interface{}) (int, error) {
return 0, nil
}
func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // ERROR `named return "num" with type "int" found`
return 0, nil
}
func funcDefintionImpl3(arg1, arg2 interface{}) (num int, _ error) { // ERROR `named return "num" with type "int" found`
return 0, nil
}
func funcDefintionImpl4(arg1, arg2 interface{}) (_ int, _ error) {
return 0, nil
}
var funcVar = func() (msg string) { // ERROR `named return "msg" with type "string" found`
msg = "c"
return msg
}
var funcVar2 = func() (_ string) {
msg := "c"
return msg
}
func test() {
a := funcVar()
_ = a
var function funcDefintion
function = funcDefintionImpl
i, err := function("", "")
_ = i
_ = err
function = funcDefintionImpl2
i, err = function("", "")
_ = i
_ = err
}
func good(i string) string {
return i
}
func bad(i string, a, b int) (ret1 string, ret2 interface{}, ret3, ret4 int, ret5 asdf) { // ERROR `named return "ret1" with type "string" found`
x := "dummy"
return fmt.Sprintf("%s", x), nil, 1, 2, asdf{}
}
func bad2() (msg string, err error) { // ERROR `named return "msg" with type "string" found`
msg = ""
err = nil
return
}
func (x) badMethod() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
_ = err
}()
func myLog(format string, args ...interface{}) {
return
}
func processError(error) {}
func doSomething() (int, error) { return 10, nil }
func multierrAppendInto(*error, error) bool { return false } // https://pkg.go.dev/go.uber.org/multierr#AppendInto
type obj struct{}
func (o *obj) func1() (err error) { return nil } // ERROR `named return "err" with type "error" found`
func (o *obj) func2() (_ error) { return nil }