-
Notifications
You must be signed in to change notification settings - Fork 265
/
use-any.go
54 lines (42 loc) 路 982 Bytes
/
use-any.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package rule
import (
"go/ast"
"github.com/mgechev/revive/lint"
)
// UseAnyRule lints given else constructs.
type UseAnyRule struct{}
// Apply applies the rule to given file.
func (r *UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
walker := lintUseAny{
onFailure: func(failure lint.Failure) {
failures = append(failures, failure)
},
}
fileAst := file.AST
ast.Walk(walker, fileAst)
return failures
}
// Name returns the rule name.
func (r *UseAnyRule) Name() string {
return "use-any"
}
type lintUseAny struct {
onFailure func(lint.Failure)
}
func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
it, ok := n.(*ast.InterfaceType)
if !ok {
return w
}
if len(it.Methods.List) != 0 {
return w // it is not and empty interface
}
w.onFailure(lint.Failure{
Node: n,
Confidence: 1,
Category: "naming",
Failure: "since GO 1.18 'interface{}' can be replaced by 'any'",
})
return w
}