-
Notifications
You must be signed in to change notification settings - Fork 25
/
XR002.go
43 lines (33 loc) · 1.14 KB
/
XR002.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
package XR002
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/resourceinforesourceonly"
)
const Doc = `check for Resource that should implement Importer
The XR002 analyzer reports missing usage of Importer in resources.`
const analyzerName = "XR002"
var Analyzer = &analysis.Analyzer{
Name: analyzerName,
Doc: Doc,
Requires: []*analysis.Analyzer{
commentignore.Analyzer,
resourceinforesourceonly.Analyzer,
},
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer)
resources := pass.ResultOf[resourceinforesourceonly.Analyzer].([]*schema.ResourceInfo)
for _, resource := range resources {
if ignorer.ShouldIgnore(analyzerName, resource.AstCompositeLit) {
continue
}
if resource.DeclaresField(schema.ResourceFieldImporter) {
continue
}
pass.Reportf(resource.AstCompositeLit.Pos(), "%s: resource should include Importer implementation", analyzerName)
}
return nil, nil
}