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 "inamedparam": checks for interface method with unnamed params #3793

Merged
merged 2 commits into from
Oct 12, 2023
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
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,7 @@ linters:
- grouper
- ifshort
- importas
- inamedparam
- ineffassign
- interfacebloat
- interfacer
Expand Down Expand Up @@ -2378,6 +2379,7 @@ linters:
- grouper
- ifshort
- importas
- inamedparam
- ineffassign
- interfacebloat
- interfacer
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ require (
github.com/ldez/tagliatelle v0.5.0
github.com/leonklingele/grouper v1.1.1
github.com/lufeee/execinquery v1.2.1
github.com/macabu/inamedparam v0.1.2
github.com/maratori/testableexamples v1.0.0
github.com/maratori/testpackage v1.1.1
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26
Expand Down
4 changes: 3 additions & 1 deletion go.sum

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

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

import (
"github.com/macabu/inamedparam"
"golang.org/x/tools/go/analysis"

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

func NewINamedParam() *goanalysis.Linter {
a := inamedparam.Analyzer

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
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 @@ -578,6 +578,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithLoadForGoAnalysis().
WithURL("https://github.com/julz/importas"),

linter.NewConfig(golinters.NewINamedParam()).
WithSince("v1.55.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/macabu/inamedparam"),

linter.NewConfig(golinters.NewIneffassign()).
WithEnabledByDefault().
WithSince("v1.0.0").
Expand Down
29 changes: 29 additions & 0 deletions test/testdata/inamedparam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//golangcitest:args -Einamedparam
package testdata

import "context"

type tStruct struct {
a int
}

type Doer interface {
Do() string
}

type NamedParam interface {
Void()

NoArgs() string

WithName(ctx context.Context, number int, toggle bool, tStruct *tStruct, doer Doer) (bool, error)

WithoutName(
context.Context, // want "interface method WithoutName must have named param for type context.Context"
int, // want "interface method WithoutName must have named param for type int"
bool, // want "interface method WithoutName must have named param for type bool"
tStruct, // want "interface method WithoutName must have named param for type tStruct"
Doer, // want "interface method WithoutName must have named param for type Doer"
struct{ b bool }, // want "interface method WithoutName must have all named params"
)
}