@@ -16,7 +16,7 @@ var Analyzer = &analysis.Analyzer{
16
16
Requires : []* analysis.Analyzer {inspect .Analyzer },
17
17
}
18
18
19
- func run (pass * analysis.Pass ) (interface {} , error ) {
19
+ func run (pass * analysis.Pass ) (any , error ) {
20
20
insp := pass .ResultOf [inspect .Analyzer ].(* inspector.Inspector )
21
21
22
22
nodeFilter := []ast.Node {
@@ -50,19 +50,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
50
50
}
51
51
52
52
argsParamType , ok := params [len (params )- 1 ].Type .(* ast.Ellipsis )
53
- if ! ok { // args are not ellipsis (...args)
53
+ if ! ok {
54
+ // args are not ellipsis (...args)
54
55
return
55
56
}
56
57
57
- elementType , ok := argsParamType .Elt .(* ast.InterfaceType )
58
- if ! ok { // args are not of interface type, but we need interface{}
58
+ if ! isAny (argsParamType ) {
59
59
return
60
60
}
61
61
62
- if elementType .Methods != nil && len (elementType .Methods .List ) != 0 {
63
- return // has >= 1 method in interface, but we need an empty interface "interface{}"
64
- }
65
-
66
62
if strings .HasSuffix (funcDecl .Name .Name , "f" ) {
67
63
return
68
64
}
@@ -73,3 +69,22 @@ func run(pass *analysis.Pass) (interface{}, error) {
73
69
74
70
return nil , nil
75
71
}
72
+
73
+ func isAny (ell * ast.Ellipsis ) bool {
74
+ switch elt := ell .Elt .(type ) {
75
+ case * ast.InterfaceType :
76
+ if elt .Methods != nil && len (elt .Methods .List ) != 0 {
77
+ // has >= 1 method in interface, but we need an empty interface "interface{}"
78
+ return false
79
+ }
80
+
81
+ return true
82
+
83
+ case * ast.Ident :
84
+ if elt .Name == "any" {
85
+ return true
86
+ }
87
+ }
88
+
89
+ return false
90
+ }
0 commit comments