forked from bflad/tfproviderlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
S034.go
51 lines (41 loc) · 1.55 KB
/
S034.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
package S034
import (
"go/ast"
"github.com/manicminer/tfproviderlint/helper/terraformtype/helper/schema"
"github.com/manicminer/tfproviderlint/passes/commentignore"
"github.com/manicminer/tfproviderlint/passes/helper/schema/schemainfo"
"golang.org/x/tools/go/analysis"
)
const Doc = `check for Schema with PromoteSingle configured
The S034 analyzer reports cases of schemas which enable PromoteSingle, which
is not valid after Terraform 0.12. Existing implementations of PromoteSingle
prior to Terraform 0.12 can be ignored currently.`
const analyzerName = "S034"
var Analyzer = &analysis.Analyzer{
Name: analyzerName,
Doc: Doc,
Requires: []*analysis.Analyzer{
commentignore.Analyzer,
schemainfo.Analyzer,
},
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer)
schemaInfos := pass.ResultOf[schemainfo.Analyzer].([]*schema.SchemaInfo)
for _, schemaInfo := range schemaInfos {
if ignorer.ShouldIgnore(analyzerName, schemaInfo.AstCompositeLit) {
continue
}
if !schemaInfo.DeclaresField(schema.SchemaFieldPromoteSingle) {
continue
}
switch t := schemaInfo.AstCompositeLit.Type.(type) {
default:
pass.Reportf(schemaInfo.AstCompositeLit.Lbrace, "%s: schema should not enable PromoteSingle (implementations prior to Terraform 0.12 can be ignored)", analyzerName)
case *ast.SelectorExpr:
pass.Reportf(t.Sel.Pos(), "%s: schema should not enable PromoteSingle (implementations prior to Terraform 0.12 can be ignored)", analyzerName)
}
}
return nil, nil
}