From 5cfb2f26159a9373dc47424fa170757857504129 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Tue, 19 Dec 2023 12:51:04 -0500 Subject: [PATCH] Bump golangci-lint to 1.55.2 and fix issues Signed-off-by: Khosrow Moossavi --- .golangci.yml | 6 ++-- Makefile | 2 +- format/doc.go | 33 ++++++++++---------- format/generator.go | 2 ++ internal/types/types.go | 4 +-- plugin/doc.go | 59 +++++++++++++++++------------------ print/doc.go | 9 +++--- print/util.go | 2 ++ scripts/docs/generate.go | 2 +- template/doc.go | 67 ++++++++++++++++++++-------------------- terraform/doc.go | 33 ++++++++++---------- 11 files changed, 108 insertions(+), 111 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 64465c3..8c75346 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,6 @@ run: timeout: 10m - deadline: 5m - - tests: true + tests: false output: format: tab @@ -100,7 +98,7 @@ linters: - goimports - gofmt # We enable this as well as goimports for its simplify mode. - prealloc - - golint + # - golint # deprecated as of upgrading to 1.55.2 - unconvert - misspell - nakedret diff --git a/Makefile b/Makefile index d017b46..437ab54 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ DOCKER_IMAGE := quay.io/$(PROJECT_OWNER)/$(PROJECT_NAME) DOCKER_TAG ?= $(DEFAULT_TAG) # Binary versions -GOLANGCI_VERSION := v1.47.2 +GOLANGCI_VERSION := v1.55.2 .PHONY: all all: clean verify checkfmt lint test build diff --git a/format/doc.go b/format/doc.go index b1a1ec8..ad71c24 100644 --- a/format/doc.go +++ b/format/doc.go @@ -10,35 +10,35 @@ the root directory of this source tree. // Package format provides different, out of the box supported, output format types. // -// Usage +// # Usage // // A specific format can be instantiated either with `format.New()` function or // directly calling its function (e.g. `NewMarkdownTable`, etc) // -// config := print.DefaultConfig() -// config.Formatter = "markdown table" +// config := print.DefaultConfig() +// config.Formatter = "markdown table" // -// formatter, err := format.New(config) -// if err != nil { -// return err -// } +// formatter, err := format.New(config) +// if err != nil { +// return err +// } // -// err := formatter.Generate(tfmodule) -// if err != nil { -// return err -// } +// err := formatter.Generate(tfmodule) +// if err != nil { +// return err +// } // -// output, err := formatter.Render"") -// if err != nil { -// return err -// } +// output, err := formatter.Render"") +// if err != nil { +// return err +// } // // Note: if you don't intend to provide additional template for the generated // content, or the target format doesn't provide templating (e.g. json, yaml, // xml, or toml) you can use `Content()` function instead of `Render)`. Note // that `Content()` returns all the sections combined with predefined order. // -// output := formatter.Content() +// output := formatter.Content() // // Supported formats are: // @@ -53,5 +53,4 @@ the root directory of this source tree. // • `NewTOML` // • `NewXML` // • `NewYAML` -// package format diff --git a/format/generator.go b/format/generator.go index e73f2ff..c3a431e 100644 --- a/format/generator.go +++ b/format/generator.go @@ -135,6 +135,8 @@ type generator struct { // newGenerator returns a generator for specific formatter name and with // provided sets of GeneratorFunc functions to build and add individual // sections. +// +//nolint:unparam func newGenerator(config *print.Config, canRender bool, fns ...generateFunc) *generator { g := &generator{ config: config, diff --git a/internal/types/types.go b/internal/types/types.go index a2b374a..2e44818 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -286,7 +286,7 @@ func (l List) Raw() interface{} { } type xmllistentry struct { - XMLName xml.Name + XMLName xml.Name `xml:"item"` Value interface{} `xml:",chardata"` } @@ -334,7 +334,7 @@ func (m Map) Length() int { } type xmlmapentry struct { - XMLName xml.Name + XMLName xml.Name `xml:","` Value interface{} `xml:",chardata"` } diff --git a/plugin/doc.go b/plugin/doc.go index 9370b15..85c7168 100644 --- a/plugin/doc.go +++ b/plugin/doc.go @@ -19,44 +19,43 @@ the root directory of this source tree. // Implementation details are hidden in go-plugin. This package is // essentially a wrapper for go-plugin. // -// Usage +// # Usage // // A simple plugin can look like this: // -// package main +// package main // -// import ( -// _ "embed" //nolint +// import ( +// _ "embed" //nolint // -// "github.com/terraform-docs/terraform-docs/plugin" -// "github.com/terraform-docs/terraform-docs/print" -// "github.com/terraform-docs/terraform-docs/template" -// "github.com/terraform-docs/terraform-docs/terraform" -// ) +// "github.com/terraform-docs/terraform-docs/plugin" +// "github.com/terraform-docs/terraform-docs/print" +// "github.com/terraform-docs/terraform-docs/template" +// "github.com/terraform-docs/terraform-docs/terraform" +// ) // -// func main() { -// plugin.Serve(&plugin.ServeOpts{ -// Name: "template", -// Version: "0.1.0", -// Printer: printerFunc, -// }) -// } +// func main() { +// plugin.Serve(&plugin.ServeOpts{ +// Name: "template", +// Version: "0.1.0", +// Printer: printerFunc, +// }) +// } // -// //go:embed sections.tmpl -// var tplCustom []byte +// //go:embed sections.tmpl +// var tplCustom []byte // -// // printerFunc the function being executed by the plugin client. -// func printerFunc(config *print.Config, module *terraform.Module) (string, error) { -// tpl := template.New(config, -// &template.Item{Name: "custom", Text: string(tplCustom)}, -// ) +// // printerFunc the function being executed by the plugin client. +// func printerFunc(config *print.Config, module *terraform.Module) (string, error) { +// tpl := template.New(config, +// &template.Item{Name: "custom", Text: string(tplCustom)}, +// ) // -// rendered, err := tpl.Render("custom", module) -// if err != nil { -// return "", err -// } -// -// return rendered, nil -// } +// rendered, err := tpl.Render("custom", module) +// if err != nil { +// return "", err +// } // +// return rendered, nil +// } package plugin diff --git a/print/doc.go b/print/doc.go index 888fff9..2e210f6 100644 --- a/print/doc.go +++ b/print/doc.go @@ -10,7 +10,7 @@ the root directory of this source tree. // Package print provides configuration, and a Generator. // -// Configuration +// # Configuration // // `print.Config` is the data structure representation for `.terraform-docs.yml` // which will be read and extracted upon execution of terraform-docs cli. On the @@ -18,13 +18,13 @@ the root directory of this source tree. // // This will return an instance of `Config` with default values set: // -// config := print.DefaultConfig() +// config := print.DefaultConfig() // // Alternatively this will return an empty instance of `Config`: // -// config := print.NewConfig() +// config := print.NewConfig() // -// Generator +// # Generator // // `Generator` is an abstract implementation of `format.Type`. It doesn't implement // `Generate(*terraform.Module) error` function. It is used directly by different @@ -46,5 +46,4 @@ the root directory of this source tree. // • `{{ .Requirements }}` // • `{{ .Resources }}` // • `{{ include "path/fo/file" }}` -// package print diff --git a/print/util.go b/print/util.go index 3d64102..6a26ef1 100644 --- a/print/util.go +++ b/print/util.go @@ -19,6 +19,7 @@ func contains(list []string, name string) bool { return false } +// nolint func index(list []string, name string) int { for i, v := range list { if v == name { @@ -28,6 +29,7 @@ func index(list []string, name string) int { return -1 } +// nolint func remove(list []string, name string) []string { index := index(list, name) if index < 0 { diff --git a/scripts/docs/generate.go b/scripts/docs/generate.go index 3c3664e..f2677bd 100644 --- a/scripts/docs/generate.go +++ b/scripts/docs/generate.go @@ -200,7 +200,7 @@ func example(ref *reference) error { if s == "" { buf.WriteString("\n") } else { - buf.WriteString(fmt.Sprintf(" %s\n", s)) + fmt.Fprintf(buf, " %s\n", s) } } ref.Example = buf.String() diff --git a/template/doc.go b/template/doc.go index 921788a..a102b01 100644 --- a/template/doc.go +++ b/template/doc.go @@ -12,43 +12,42 @@ the root directory of this source tree. // // Usage // -// import ( -// "fmt" -// gotemplate "text/template" +// import ( +// "fmt" +// gotemplate "text/template" // -// "github.com/terraform-docs/terraform-docs/print" -// "github.com/terraform-docs/terraform-docs/template" -// "github.com/terraform-docs/terraform-docs/terraform" -// ) +// "github.com/terraform-docs/terraform-docs/print" +// "github.com/terraform-docs/terraform-docs/template" +// "github.com/terraform-docs/terraform-docs/terraform" +// ) // -// const mainTpl =` -// {{- if .Config.Sections.Header -}} -// {{- with .Module.Header -}} -// {{ colorize "\033[90m" . }} -// {{ end -}} -// {{- printf "\n\n" -}} -// {{ end -}}` +// const mainTpl =` +// {{- if .Config.Sections.Header -}} +// {{- with .Module.Header -}} +// {{ colorize "\033[90m" . }} +// {{ end -}} +// {{- printf "\n\n" -}} +// {{ end -}}` // -// func render(config *print.Config, module *terraform.Module) (string, error) { -// tt := template.New(config, &template.Item{ -// Name: "main", -// Text: mainTpl, -// TrimSpace: true, -// }) +// func render(config *print.Config, module *terraform.Module) (string, error) { +// tt := template.New(config, &template.Item{ +// Name: "main", +// Text: mainTpl, +// TrimSpace: true, +// }) // -// tt := template.New(config, items...) -// tt.CustomFunc(gotemplate.FuncMap{ -// "colorize": func(color string, s string) string { -// reset := "\033[0m" -// if !config.Settings.Color { -// color = "" -// reset = "" -// } -// return fmt.Sprintf("%s%s%s", color, s, reset) -// }, -// }) -// -// return tt.Render("main", module) -// } +// tt := template.New(config, items...) +// tt.CustomFunc(gotemplate.FuncMap{ +// "colorize": func(color string, s string) string { +// reset := "\033[0m" +// if !config.Settings.Color { +// color = "" +// reset = "" +// } +// return fmt.Sprintf("%s%s%s", color, s, reset) +// }, +// }) // +// return tt.Render("main", module) +// } package template diff --git a/terraform/doc.go b/terraform/doc.go index 1708dc8..c55057d 100644 --- a/terraform/doc.go +++ b/terraform/doc.go @@ -30,23 +30,22 @@ the root directory of this source tree. // // Usage // -// options := &terraform.Options{ -// Path: "./examples", -// ShowHeader: true, -// HeaderFromFile: "main.tf", -// ShowFooter: true, -// FooterFromFile: "footer.md", -// SortBy: &terraform.SortBy{ -// Name: true, -// }, -// ReadComments: true, -// } +// options := &terraform.Options{ +// Path: "./examples", +// ShowHeader: true, +// HeaderFromFile: "main.tf", +// ShowFooter: true, +// FooterFromFile: "footer.md", +// SortBy: &terraform.SortBy{ +// Name: true, +// }, +// ReadComments: true, +// } // -// tfmodule, err := terraform.LoadWithOptions(options) -// if err != nil { -// log.Fatal(err) -// } -// -// ... +// tfmodule, err := terraform.LoadWithOptions(options) +// if err != nil { +// log.Fatal(err) +// } // +// ... package terraform