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

Add nonamedreturns linter #2701

Merged
merged 21 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ linters-settings:
- ifaceassert
- loopclosure
- lostcancel
- namedreturnlint
- nilfunc
- nilness
- printf
Expand Down Expand Up @@ -831,6 +832,7 @@ linters-settings:
- ifaceassert
- loopclosure
- lostcancel
- namedreturnlint
- nilfunc
- nilness
- printf
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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/namedreturnlint v1.0.0
github.com/fzipp/gocyclo v0.5.0
github.com/go-critic/go-critic v0.6.2
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
Expand Down Expand Up @@ -161,7 +162,7 @@ require (
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum

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

18 changes: 18 additions & 0 deletions pkg/golinters/namedreturnlint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package golinters

import (
"github.com/firefart/namedreturnlint/analyzer"

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

"golang.org/x/tools/go/analysis"
)
firefart marked this conversation as resolved.
Show resolved Hide resolved

func NewNamedReturnLint() *goanalysis.Linter {
return goanalysis.NewLinter(
"namedreturnlint",
"Checks for named returns",
[]*analysis.Analyzer{analyzer.Analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
5 changes: 5 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithURL("https://github.com/alexkohler/nakedret"),

linter.NewConfig(golinters.NewNamedReturnLint()).
WithSince("v1.46.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/FireFart/namedreturnlint"),

linter.NewConfig(golinters.NewNestif()).
WithSince("v1.25.0").
WithPresets(linter.PresetComplexity).
Expand Down
25 changes: 25 additions & 0 deletions test/testdata/namedreturnlint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//args: -Enamedreturnlint
package testdata

import "fmt"

type asdf struct {
test string
}

func noParams() {
return
}

func argl(i string, a, b int) (ret1 string, ret2 interface{}, ret3, ret4 int, ret5 asdf) { // ERROR `named return ret1 \(string\) found in function argl`
x := "dummy"
return fmt.Sprintf("%s", x), nil, 1, 2, asdf{}
}

func good(i string) string {
return i
}

func myLog(format string, args ...interface{}) {
return
}