-
Notifications
You must be signed in to change notification settings - Fork 25
/
valuechangevalidationfuncinfo.go
40 lines (33 loc) · 1.11 KB
/
valuechangevalidationfuncinfo.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
package valuechangevalidationfuncinfo
import (
"go/ast"
"reflect"
"github.com/bflad/tfproviderlint/helper/terraformtype/helper/customdiff"
"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: "valuechangevalidationfuncinfo",
Doc: "find github.com/hashicorp/terraform-plugin-sdk/helper/customdiff ValueChangeValidationFunc declarations for later passes",
Requires: []*analysis.Analyzer{
inspect.Analyzer,
},
Run: run,
ResultType: reflect.TypeOf([]*customdiff.ValueChangeValidationFuncInfo{}),
}
func run(pass *analysis.Pass) (interface{}, error) {
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
nodeFilter := []ast.Node{
(*ast.FuncDecl)(nil),
(*ast.FuncLit)(nil),
}
var result []*customdiff.ValueChangeValidationFuncInfo
inspect.Preorder(nodeFilter, func(n ast.Node) {
if !customdiff.IsFuncTypeValueChangeValidationFunc(n, pass.TypesInfo) {
return
}
result = append(result, customdiff.NewValueChangeValidationFuncInfo(n, pass.TypesInfo))
})
return result, nil
}