-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathR003.go
49 lines (38 loc) · 1.28 KB
/
R003.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
// Package R003 defines an Analyzer that checks for
// Resource having Exists functions
package R003
import (
"golang.org/x/tools/go/analysis"
"github.com/bflad/tfproviderlint/helper/terraformtype/helper/schema"
"github.com/bflad/tfproviderlint/passes/commentignore"
"github.com/bflad/tfproviderlint/passes/helper/schema/resourceinfo"
)
const Doc = `check for Resource having Exists functions
The R003 analyzer reports likely extraneous uses of Exists
functions for a resource. Exists logic can be handled inside the Read function
to prevent logic duplication.`
const analyzerName = "R003"
var Analyzer = &analysis.Analyzer{
Name: analyzerName,
Doc: Doc,
Requires: []*analysis.Analyzer{
resourceinfo.Analyzer,
commentignore.Analyzer,
},
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer)
resources := pass.ResultOf[resourceinfo.Analyzer].([]*schema.ResourceInfo)
for _, resource := range resources {
if ignorer.ShouldIgnore(analyzerName, resource.AstCompositeLit) {
continue
}
kvExpr := resource.Fields[schema.ResourceFieldExists]
if kvExpr == nil {
continue
}
pass.Reportf(kvExpr.Key.Pos(), "%s: resource should not include Exists function", analyzerName)
}
return nil, nil
}