Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.reference.yml
Expand Up @@ -1154,6 +1154,11 @@ linters-settings:
# Default: false
require-specific: true

nonamedreturns:
# Do not complain about named error, if it is assigned inside defer.
# Default: false
allow-error-in-defer: true

paralleltest:
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
# Default: false
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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.1
github.com/firefart/nonamedreturns v1.0.2
github.com/fzipp/gocyclo v0.5.1
github.com/go-critic/go-critic v0.6.3
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/config/linters_settings.go
Expand Up @@ -158,6 +158,7 @@ type LintersSettings struct {
NilNil NilNilSettings
Nlreturn NlreturnSettings
NoLintLint NoLintLintSettings
NoNamedReturns NoNamedReturnsSettings
ParallelTest ParallelTestSettings
Prealloc PreallocSettings
Predeclared PredeclaredSettings
Expand Down Expand Up @@ -484,6 +485,9 @@ type NoLintLintSettings struct {
AllowUnused bool `mapstructure:"allow-unused"`
}

type NoNamedReturnsSettings struct {
AllowErrorInDefer bool `mapstructure:"allow-error-in-defer"`
}
type ParallelTestSettings struct {
IgnoreMissing bool `mapstructure:"ignore-missing"`
}
Expand Down
22 changes: 17 additions & 5 deletions pkg/golinters/nonamedreturns.go
Expand Up @@ -4,14 +4,26 @@ import (
"github.com/firefart/nonamedreturns/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewNoNamedReturns() *goanalysis.Linter {
func NewNoNamedReturns(settings *config.NoNamedReturnsSettings) *goanalysis.Linter {
a := analyzer.Analyzer

var cfg map[string]map[string]interface{}
if settings != nil {
cfg = map[string]map[string]interface{}{
a.Name: {
analyzer.FlagAllowErrorInDefer: settings.AllowErrorInDefer,
},
}
}

return goanalysis.NewLinter(
"nonamedreturns",
"Reports all named returns",
[]*analysis.Analyzer{analyzer.Analyzer},
nil,
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
cfg,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
4 changes: 3 additions & 1 deletion pkg/lint/lintersdb/manager.go
Expand Up @@ -147,6 +147,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
nilNilCfg *config.NilNilSettings
nlreturnCfg *config.NlreturnSettings
noLintLintCfg *config.NoLintLintSettings
noNamedReturnsCfg *config.NoNamedReturnsSettings
parallelTestCfg *config.ParallelTestSettings
preallocCfg *config.PreallocSettings
predeclaredCfg *config.PredeclaredSettings
Expand Down Expand Up @@ -216,6 +217,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
nilNilCfg = &m.cfg.LintersSettings.NilNil
nlreturnCfg = &m.cfg.LintersSettings.Nlreturn
noLintLintCfg = &m.cfg.LintersSettings.NoLintLint
noNamedReturnsCfg = &m.cfg.LintersSettings.NoNamedReturns
preallocCfg = &m.cfg.LintersSettings.Prealloc
parallelTestCfg = &m.cfg.LintersSettings.ParallelTest
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
Expand Down Expand Up @@ -623,7 +625,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithURL("https://github.com/sonatard/noctx").
WithNoopFallback(m.cfg),

linter.NewConfig(golinters.NewNoNamedReturns()).
linter.NewConfig(golinters.NewNoNamedReturns(noNamedReturnsCfg)).
WithSince("v1.46.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/firefart/nonamedreturns"),
Expand Down
3 changes: 3 additions & 0 deletions test/testdata/configs/nonamedreturns.yml
@@ -0,0 +1,3 @@
linters-settings:
nonamedreturns:
allow-error-in-defer: true
32 changes: 31 additions & 1 deletion test/testdata/nonamedreturns.go
@@ -1,4 +1,4 @@
//args: -Enonamedreturns
// args: -Enonamedreturns
package testdata

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

var e2 = func() (_ error) {
return
}

func deferWithError() (err error) { // ERROR `named return "err" with type "error" found`
defer func() {
err = nil // use flag to allow this
}()
return
}

var (
f = func() {
return
Expand All @@ -37,6 +48,10 @@ var (
err = nil
return
}

h2 = func() (_ error) {
return
}
)

// this should not match as the implementation does not need named parameters (see below)
Expand All @@ -50,11 +65,24 @@ func funcDefintionImpl2(arg1, arg2 interface{}) (num int, err error) { // ERROR
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
Expand Down Expand Up @@ -92,3 +120,5 @@ func myLog(format string, args ...interface{}) {
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 }