forked from bflad/tfproviderlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testfuncdecl.go
41 lines (33 loc) · 840 Bytes
/
testfuncdecl.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
package testfuncdecl
import (
"go/ast"
"reflect"
"strings"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
)
var Analyzer = &analysis.Analyzer{
Name: "testfuncdecl",
Doc: "find *ast.FuncDecl with Test prefixed names for later passes",
Requires: []*analysis.Analyzer{
inspect.Analyzer,
},
Run: run,
ResultType: reflect.TypeOf([]*ast.FuncDecl{}),
}
func run(pass *analysis.Pass) (interface{}, error) {
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
nodeFilter := []ast.Node{
(*ast.FuncDecl)(nil),
}
var result []*ast.FuncDecl
inspect.Preorder(nodeFilter, func(n ast.Node) {
x := n.(*ast.FuncDecl)
if !strings.HasPrefix(x.Name.Name, "Test") {
return
}
result = append(result, x)
})
return result, nil
}