forked from bflad/tfproviderlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemainfocomputedonly.go
35 lines (27 loc) · 938 Bytes
/
schemainfocomputedonly.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
package schemainfocomputedonly
import (
"reflect"
"github.com/bflad/tfproviderlint/helper/terraformtype/helper/schema"
"github.com/bflad/tfproviderlint/passes/helper/schema/schemainfo"
"golang.org/x/tools/go/analysis"
)
var Analyzer = &analysis.Analyzer{
Name: "schemainfocomputedonly",
Doc: "find github.com/hashicorp/terraform-plugin-sdk/helper/schema.Schema literals with Computed: true only for later passes",
Requires: []*analysis.Analyzer{
schemainfo.Analyzer,
},
Run: run,
ResultType: reflect.TypeOf([]*schema.SchemaInfo{}),
}
func run(pass *analysis.Pass) (interface{}, error) {
schemaInfos := pass.ResultOf[schemainfo.Analyzer].([]*schema.SchemaInfo)
var result []*schema.SchemaInfo
for _, schemaInfo := range schemaInfos {
if !schemaInfo.Schema.Computed || schemaInfo.Schema.Optional || schemaInfo.Schema.Required {
continue
}
result = append(result, schemaInfo)
}
return result, nil
}