diff --git a/format/asciidoc_document.go b/format/asciidoc_document.go index 260d833..2059e86 100644 --- a/format/asciidoc_document.go +++ b/format/asciidoc_document.go @@ -69,7 +69,7 @@ func NewAsciidocDocument(config *print.Config) Type { // Generate a Terraform module as AsciiDoc document. func (d *asciidocDocument) Generate(module *terraform.Module) error { - err := d.generator.forEach(func(name string) (string, error) { + err := d.forEach(func(name string) (string, error) { rendered, err := d.template.Render(name, module) if err != nil { return "", err @@ -77,7 +77,7 @@ func (d *asciidocDocument) Generate(module *terraform.Module) error { return sanitize(rendered), nil }) - d.generator.funcs(withModule(module)) + d.funcs(withModule(module)) return err } diff --git a/format/asciidoc_table.go b/format/asciidoc_table.go index c8cd675..a31f700 100644 --- a/format/asciidoc_table.go +++ b/format/asciidoc_table.go @@ -60,7 +60,7 @@ func NewAsciidocTable(config *print.Config) Type { // Generate a Terraform module as AsciiDoc tables. func (t *asciidocTable) Generate(module *terraform.Module) error { - err := t.generator.forEach(func(name string) (string, error) { + err := t.forEach(func(name string) (string, error) { rendered, err := t.template.Render(name, module) if err != nil { return "", err @@ -68,7 +68,7 @@ func (t *asciidocTable) Generate(module *terraform.Module) error { return sanitize(rendered), nil }) - t.generator.funcs(withModule(module)) + t.funcs(withModule(module)) return err } diff --git a/format/json.go b/format/json.go index 357ca9f..34a58c5 100644 --- a/format/json.go +++ b/format/json.go @@ -47,7 +47,7 @@ func (j *json) Generate(module *terraform.Module) error { return err } - j.generator.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) + j.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) return nil } diff --git a/format/markdown_document.go b/format/markdown_document.go index 23f8982..b029166 100644 --- a/format/markdown_document.go +++ b/format/markdown_document.go @@ -67,7 +67,7 @@ func NewMarkdownDocument(config *print.Config) Type { // Generate a Terraform module as Markdown document. func (d *markdownDocument) Generate(module *terraform.Module) error { - err := d.generator.forEach(func(name string) (string, error) { + err := d.forEach(func(name string) (string, error) { rendered, err := d.template.Render(name, module) if err != nil { return "", err @@ -75,7 +75,7 @@ func (d *markdownDocument) Generate(module *terraform.Module) error { return sanitize(rendered), nil }) - d.generator.funcs(withModule(module)) + d.funcs(withModule(module)) return err } diff --git a/format/markdown_table.go b/format/markdown_table.go index 19214d6..6d42bce 100644 --- a/format/markdown_table.go +++ b/format/markdown_table.go @@ -58,7 +58,7 @@ func NewMarkdownTable(config *print.Config) Type { // Generate a Terraform module as Markdown tables. func (t *markdownTable) Generate(module *terraform.Module) error { - err := t.generator.forEach(func(name string) (string, error) { + err := t.forEach(func(name string) (string, error) { rendered, err := t.template.Render(name, module) if err != nil { return "", err @@ -66,7 +66,7 @@ func (t *markdownTable) Generate(module *terraform.Module) error { return sanitize(rendered), nil }) - t.generator.funcs(withModule(module)) + t.funcs(withModule(module)) return err } diff --git a/format/pretty.go b/format/pretty.go index 68f51e2..f33acea 100644 --- a/format/pretty.go +++ b/format/pretty.go @@ -64,8 +64,8 @@ func (p *pretty) Generate(module *terraform.Module) error { return err } - p.generator.funcs(withContent(regexp.MustCompile(`(\r?\n)*$`).ReplaceAllString(rendered, ""))) - p.generator.funcs(withModule(module)) + p.funcs(withContent(regexp.MustCompile(`(\r?\n)*$`).ReplaceAllString(rendered, ""))) + p.funcs(withModule(module)) return nil } diff --git a/format/tfvars_hcl.go b/format/tfvars_hcl.go index 4364f5c..d1e13ba 100644 --- a/format/tfvars_hcl.go +++ b/format/tfvars_hcl.go @@ -76,7 +76,7 @@ func (h *tfvarsHCL) Generate(module *terraform.Module) error { return err } - h.generator.funcs(withContent(strings.TrimSuffix(sanitize(rendered), "\n"))) + h.funcs(withContent(strings.TrimSuffix(sanitize(rendered), "\n"))) return nil } diff --git a/format/tfvars_json.go b/format/tfvars_json.go index c6203f8..34bde2a 100644 --- a/format/tfvars_json.go +++ b/format/tfvars_json.go @@ -53,7 +53,7 @@ func (j *tfvarsJSON) Generate(module *terraform.Module) error { return err } - j.generator.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) + j.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) return nil } diff --git a/format/toml.go b/format/toml.go index ce46298..15ce1bd 100644 --- a/format/toml.go +++ b/format/toml.go @@ -46,7 +46,7 @@ func (t *toml) Generate(module *terraform.Module) error { return err } - t.generator.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) + t.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) return nil diff --git a/format/xml.go b/format/xml.go index 1093e94..ba6c817 100644 --- a/format/xml.go +++ b/format/xml.go @@ -42,7 +42,7 @@ func (x *xml) Generate(module *terraform.Module) error { return err } - x.generator.funcs(withContent(strings.TrimSuffix(string(out), "\n"))) + x.funcs(withContent(strings.TrimSuffix(string(out), "\n"))) return nil } diff --git a/format/yaml.go b/format/yaml.go index a12a125..52ca58c 100644 --- a/format/yaml.go +++ b/format/yaml.go @@ -47,7 +47,7 @@ func (y *yaml) Generate(module *terraform.Module) error { return err } - y.generator.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) + y.funcs(withContent(strings.TrimSuffix(buffer.String(), "\n"))) return nil } diff --git a/internal/plugin/discovery.go b/internal/plugin/discovery.go index b6c611f..99dbfe8 100644 --- a/internal/plugin/discovery.go +++ b/internal/plugin/discovery.go @@ -11,6 +11,7 @@ the root directory of this source tree. package plugin import ( + "context" "fmt" "os" "os/exec" @@ -71,7 +72,7 @@ func findPlugins(dir string) (*List, error) { // path on the fly per directory. // // nolint:gosec - cmd := exec.Command(path) + cmd := exec.CommandContext(context.TODO(), path) client := pluginsdk.NewClient(&pluginsdk.ClientOpts{ Cmd: cmd, diff --git a/plugin/plugin.go b/plugin/plugin.go index 9540476..7104184 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -19,6 +19,9 @@ import ( "github.com/terraform-docs/terraform-docs/internal/types" ) +// Ensure formatter fully satisfy plugin interface. +var _ goplugin.Plugin = &formatter{} + // handshakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes. var handshakeConfig = goplugin.HandshakeConfig{ ProtocolVersion: 7, @@ -59,7 +62,7 @@ func (f *formatter) Server(b *goplugin.MuxBroker) (interface{}, error) { } // Client returns an RPC client for the host. -func (formatter) Client(b *goplugin.MuxBroker, c *rpc.Client) (interface{}, error) { +func (*formatter) Client(b *goplugin.MuxBroker, c *rpc.Client) (interface{}, error) { return &Client{rpcClient: c, broker: b}, nil } diff --git a/print/config.go b/print/config.go index 4ac1935..cd8534e 100644 --- a/print/config.go +++ b/print/config.go @@ -287,7 +287,7 @@ func (o *output) validate() error { for _, t := range tests { if t.condition() { - return fmt.Errorf(t.errMessage) + return fmt.Errorf("%s", t.errMessage) } } diff --git a/template/template.go b/template/template.go index 4fa5ef1..b89ce1a 100644 --- a/template/template.go +++ b/template/template.go @@ -51,7 +51,7 @@ func New(config *print.Config, items ...*Item) *Template { } // Funcs return available template out of the box and custom functions. -func (t Template) Funcs() gotemplate.FuncMap { +func (t *Template) Funcs() gotemplate.FuncMap { return t.funcMap } diff --git a/terraform/load.go b/terraform/load.go index 55dfc72..12f48ef 100644 --- a/terraform/load.go +++ b/terraform/load.go @@ -11,6 +11,7 @@ the root directory of this source tree. package terraform import ( + "context" "encoding/json" "errors" "fmt" @@ -336,7 +337,7 @@ func loadOutputValues(config *print.Config) (map[string]*output, error) { var out []byte var err error if config.OutputValues.From == "" { - cmd := exec.Command("terraform", "output", "-json") + cmd := exec.CommandContext(context.TODO(), "terraform", "output", "-json") cmd.Dir = config.ModuleRoot if out, err = cmd.Output(); err != nil { return nil, fmt.Errorf("caught error while reading the terraform outputs: %w", err)