-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathXS001.go
58 lines (46 loc) · 1.7 KB
/
XS001.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
52
53
54
55
56
57
58
// Package XS001 defines an Analyzer that checks for
// Schema that Description is configured
package XS001
import (
"go/ast"
"github.com/bflad/tfproviderlint/helper/terraformtype/helper/schema"
"github.com/bflad/tfproviderlint/passes/commentignore"
"github.com/bflad/tfproviderlint/passes/helper/schema/schemamapcompositelit"
"golang.org/x/tools/go/analysis"
)
const Doc = `check for Schema that Description is configured
The XS001 analyzer reports cases of schemas where Description is not
configured, which is generally useful for providers that wish to
automatically generate documentation based on the schema information.`
const analyzerName = "XS001"
var Analyzer = &analysis.Analyzer{
Name: analyzerName,
Doc: Doc,
Requires: []*analysis.Analyzer{
schemamapcompositelit.Analyzer,
commentignore.Analyzer,
},
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer)
schemamapcompositelits := pass.ResultOf[schemamapcompositelit.Analyzer].([]*ast.CompositeLit)
for _, smap := range schemamapcompositelits {
for _, schemaCompositeLit := range schema.GetSchemaMapSchemas(smap) {
schemaInfo := schema.NewSchemaInfo(schemaCompositeLit, pass.TypesInfo)
if ignorer.ShouldIgnore(analyzerName, schemaInfo.AstCompositeLit) {
continue
}
if schemaInfo.Fields["Description"] != nil {
continue
}
switch t := schemaInfo.AstCompositeLit.Type.(type) {
default:
pass.Reportf(schemaInfo.AstCompositeLit.Lbrace, "%s: schema should configure Description", analyzerName)
case *ast.SelectorExpr:
pass.Reportf(t.Sel.Pos(), "%s: schema should configure Description", analyzerName)
}
}
}
return nil, nil
}