-
Notifications
You must be signed in to change notification settings - Fork 5
/
contents.go
66 lines (51 loc) · 1.36 KB
/
contents.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
59
60
61
62
63
64
65
66
package check
import (
"fmt"
"github.com/bflad/tfproviderdocs/check/contents"
)
type ContentsCheck struct {
Options *ContentsOptions
}
// ContentsOptions represents configuration options for Contents.
type ContentsOptions struct {
*FileOptions
Enable bool
ProviderName string
RequireSchemaOrdering bool
}
func NewContentsCheck(opts *ContentsOptions) *ContentsCheck {
check := &ContentsCheck{
Options: opts,
}
if check.Options == nil {
check.Options = &ContentsOptions{}
}
if check.Options.FileOptions == nil {
check.Options.FileOptions = &FileOptions{}
}
return check
}
func (check *ContentsCheck) Run(path string, exampleLanguage string) error {
if !check.Options.Enable {
return nil
}
checkOpts := &contents.CheckOptions{
ArgumentsSection: &contents.CheckArgumentsSectionOptions{
RequireSchemaOrdering: check.Options.RequireSchemaOrdering,
},
AttributesSection: &contents.CheckAttributesSectionOptions{
RequireSchemaOrdering: check.Options.RequireSchemaOrdering,
},
ExamplesSection: &contents.CheckExamplesSectionOptions{
ExpectedCodeBlockLanguage: exampleLanguage,
},
}
doc := contents.NewDocument(path, check.Options.ProviderName)
if err := doc.Parse(); err != nil {
return fmt.Errorf("error parsing file: %w", err)
}
if err := doc.Check(checkOpts); err != nil {
return err
}
return nil
}