Skip to content

Commit 4b188db

Browse files
macabuldez
andauthored
Add "inamedparam": checks for interface method with unnamed params (#3793)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 6491317 commit 4b188db

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

Diff for: .golangci.reference.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,7 @@ linters:
22632263
- grouper
22642264
- ifshort
22652265
- importas
2266+
- inamedparam
22662267
- ineffassign
22672268
- interfacebloat
22682269
- interfacer
@@ -2380,6 +2381,7 @@ linters:
23802381
- grouper
23812382
- ifshort
23822383
- importas
2384+
- inamedparam
23832385
- ineffassign
23842386
- interfacebloat
23852387
- interfacer

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ require (
6767
github.com/ldez/tagliatelle v0.5.0
6868
github.com/leonklingele/grouper v1.1.1
6969
github.com/lufeee/execinquery v1.2.1
70+
github.com/macabu/inamedparam v0.1.2
7071
github.com/maratori/testableexamples v1.0.0
7172
github.com/maratori/testpackage v1.1.1
7273
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26

Diff for: go.sum

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/golinters/inamedparam.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"github.com/macabu/inamedparam"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewINamedParam() *goanalysis.Linter {
11+
a := inamedparam.Analyzer
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeSyntax)
19+
}

Diff for: pkg/lint/lintersdb/manager.go

+5
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
578578
WithLoadForGoAnalysis().
579579
WithURL("https://github.com/julz/importas"),
580580

581+
linter.NewConfig(golinters.NewINamedParam()).
582+
WithSince("v1.55.0").
583+
WithPresets(linter.PresetStyle).
584+
WithURL("https://github.com/macabu/inamedparam"),
585+
581586
linter.NewConfig(golinters.NewIneffassign()).
582587
WithEnabledByDefault().
583588
WithSince("v1.0.0").

Diff for: test/testdata/inamedparam.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//golangcitest:args -Einamedparam
2+
package testdata
3+
4+
import "context"
5+
6+
type tStruct struct {
7+
a int
8+
}
9+
10+
type Doer interface {
11+
Do() string
12+
}
13+
14+
type NamedParam interface {
15+
Void()
16+
17+
NoArgs() string
18+
19+
WithName(ctx context.Context, number int, toggle bool, tStruct *tStruct, doer Doer) (bool, error)
20+
21+
WithoutName(
22+
context.Context, // want "interface method WithoutName must have named param for type context.Context"
23+
int, // want "interface method WithoutName must have named param for type int"
24+
bool, // want "interface method WithoutName must have named param for type bool"
25+
tStruct, // want "interface method WithoutName must have named param for type tStruct"
26+
Doer, // want "interface method WithoutName must have named param for type Doer"
27+
struct{ b bool }, // want "interface method WithoutName must have all named params"
28+
)
29+
}

0 commit comments

Comments
 (0)