aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/macabu/inamedparam/inamedparam.go
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-04 17:40:11 +0000
committerTaras Madan <tarasmadan@google.com>2024-03-04 18:34:55 +0000
commit5fc5366972c874b919f93165bb4ed4e2bcb7c350 (patch)
tree287c3361a0dee0c72af80d9a1a66714a06e98a62 /vendor/github.com/macabu/inamedparam/inamedparam.go
parent1be5ce38a9059c356eb193a8c34d60d61c9fc31f (diff)
mod: bump github.com/golangci/golangci-lint from 1.55.2 to 1.56.2
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.55.2 to 1.56.2. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.56.2) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/macabu/inamedparam/inamedparam.go')
-rw-r--r--vendor/github.com/macabu/inamedparam/inamedparam.go33
1 files changed, 30 insertions, 3 deletions
diff --git a/vendor/github.com/macabu/inamedparam/inamedparam.go b/vendor/github.com/macabu/inamedparam/inamedparam.go
index 433e04e5b..8ba7fe188 100644
--- a/vendor/github.com/macabu/inamedparam/inamedparam.go
+++ b/vendor/github.com/macabu/inamedparam/inamedparam.go
@@ -1,6 +1,7 @@
package inamedparam
import (
+ "flag"
"go/ast"
"golang.org/x/tools/go/analysis"
@@ -8,15 +9,30 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
+const (
+ analyzerName = "inamedparam"
+
+ flagSkipSingleParam = "skip-single-param"
+)
+
var Analyzer = &analysis.Analyzer{
- Name: "inamedparam",
- Doc: "reports interfaces with unnamed method parameters",
- Run: run,
+ Name: analyzerName,
+ Doc: "reports interfaces with unnamed method parameters",
+ Run: run,
+ Flags: flags(),
Requires: []*analysis.Analyzer{
inspect.Analyzer,
},
}
+func flags() flag.FlagSet {
+ flags := flag.NewFlagSet(analyzerName, flag.ExitOnError)
+
+ flags.Bool(flagSkipSingleParam, false, "skip interface methods with a single unnamed parameter")
+
+ return *flags
+}
+
func run(pass *analysis.Pass) (interface{}, error) {
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
@@ -24,6 +40,8 @@ func run(pass *analysis.Pass) (interface{}, error) {
&ast.InterfaceType{},
}
+ skipSingleParam := pass.Analyzer.Flags.Lookup(flagSkipSingleParam).Value.(flag.Getter).Get().(bool)
+
inspect.Preorder(types, func(n ast.Node) {
interfaceType, ok := n.(*ast.InterfaceType)
if !ok || interfaceType == nil || interfaceType.Methods == nil {
@@ -36,8 +54,17 @@ func run(pass *analysis.Pass) (interface{}, error) {
continue
}
+ // Improvement: add test case to reproduce this. Help wanted.
+ if len(method.Names) == 0 {
+ continue
+ }
+
methodName := method.Names[0].Name
+ if skipSingleParam && len(interfaceFunc.Params.List) == 1 {
+ continue
+ }
+
for _, param := range interfaceFunc.Params.List {
if param.Names == nil {
var builtParamType string