Skip to content

Commit

Permalink
Add "inamedparam": checks for interface method with unnamed params
Browse files Browse the repository at this point in the history
  • Loading branch information
macabu committed Aug 2, 2023
1 parent e555470 commit 317d4a6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ linters:
- grouper
- ifshort
- importas
- inamedparam
- ineffassign
- interfacebloat
- interfacer
Expand Down Expand Up @@ -2272,6 +2273,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 @@ -64,6 +64,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
6 changes: 3 additions & 3 deletions go.sum

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

21 changes: 21 additions & 0 deletions pkg/golinters/inamedparam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 {
analyzer := inamedparam.Analyzer

return goanalysis.NewLinter(
analyzer.Name,
analyzer.Doc,
[]*analysis.Analyzer{
analyzer,
},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithLoadForGoAnalysis().
WithURL("https://github.com/julz/importas"),

linter.NewConfig(golinters.NewINamedParam()).
WithSince("v1.54.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
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"
)
}

0 comments on commit 317d4a6

Please sign in to comment.