chore: fix golangci-lint issues

Signed-off-by: Pascal Hofmann <mail@pascalhofmann.de>
This commit is contained in:
Pascal Hofmann
2025-12-12 14:21:54 +01:00
parent 4ac0a6a524
commit dd450a5352
16 changed files with 26 additions and 21 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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)