From 0ae8e4f2cbe418b5262b7f6d1acfe69d9de3e4e4 Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Sun, 21 Dec 2025 11:43:28 -0800 Subject: [PATCH] [dev-v3] Bump Go v1.25, `golangci-lint` v2 Signed-off-by: George Jenkins --- .github/env | 4 +- .golangci.yml | 93 ++++++++++++------- cmd/helm/docs.go | 2 +- cmd/helm/repo_update.go | 3 +- cmd/helm/template.go | 2 +- go.mod | 2 +- internal/test/test.go | 2 +- internal/third_party/dep/fs/fs.go | 12 +-- internal/third_party/dep/fs/fs_test.go | 19 ---- .../deployment/util/deploymentutil.go | 2 +- pkg/action/install.go | 2 +- pkg/engine/lookup_func.go | 2 +- pkg/registry/utils_test.go | 5 +- pkg/time/time.go | 2 +- pkg/time/time_test.go | 2 +- 15 files changed, 77 insertions(+), 77 deletions(-) diff --git a/.github/env b/.github/env index da6212635..9d79b174f 100644 --- a/.github/env +++ b/.github/env @@ -1,2 +1,2 @@ -GOLANG_VERSION=1.24 -GOLANGCI_LINT_VERSION=v1.64 +GOLANG_VERSION=1.25 +GOLANGCI_LINT_VERSION=v2.5.0 diff --git a/.golangci.yml b/.golangci.yml index a3e5119d4..ae0921560 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,45 +1,66 @@ -run: - timeout: 10m - +version: "2" linters: - disable-all: true + default: none enable: - dupl - - gofmt - - goimports - - gosimple - govet - ineffassign - misspell - nakedret - revive - - unused - staticcheck - -linters-settings: - gofmt: - simplify: true - goimports: - local-prefixes: helm.sh/helm/v3 - dupl: - threshold: 400 -issues: - exclude-rules: - # Helm, and the Go source code itself, sometimes uses these names outside their built-in - # functions. As the Go source code has re-used these names it's ok for Helm to do the same. - # Linting will look for redefinition of built-in id's but we opt-in to the ones we choose to use. - - linters: - - revive - text: "redefines-builtin-id: redefinition of the built-in function append" - - linters: - - revive - text: "redefines-builtin-id: redefinition of the built-in function clear" - - linters: - - revive - text: "redefines-builtin-id: redefinition of the built-in function max" - - linters: - - revive - text: "redefines-builtin-id: redefinition of the built-in function min" - - linters: - - revive - text: "redefines-builtin-id: redefinition of the built-in function new" + - unused + settings: + dupl: + threshold: 400 + staticcheck: + checks: + - "all" + - "-QF1008" # QF1008: could remove embedded field "Foo" from selector + - "-QF1001" # QF1001: could apply De Morgan's law + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + # Helm, and the Go source code itself, sometimes uses these names outside their built-in + # functions. As the Go source code has re-used these names it's ok for Helm to do the same. + # Linting will look for redefinition of built-in id's but we opt-in to the ones we choose to use. + - linters: + - revive + text: 'redefines-builtin-id: redefinition of the built-in function append' + - linters: + - revive + text: 'redefines-builtin-id: redefinition of the built-in function clear' + - linters: + - revive + text: 'redefines-builtin-id: redefinition of the built-in function max' + - linters: + - revive + text: 'redefines-builtin-id: redefinition of the built-in function min' + - linters: + - revive + text: 'redefines-builtin-id: redefinition of the built-in function new' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + settings: + gofmt: + simplify: true + goimports: + local-prefixes: + - helm.sh/helm/v3 + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/cmd/helm/docs.go b/cmd/helm/docs.go index dd0cf60c7..91e2ea79f 100644 --- a/cmd/helm/docs.go +++ b/cmd/helm/docs.go @@ -86,7 +86,7 @@ func (o *docsOptions) run(_ io.Writer) error { hdrFunc := func(filename string) string { base := filepath.Base(filename) name := strings.TrimSuffix(base, path.Ext(base)) - title := cases.Title(language.Und, cases.NoLower).String(strings.Replace(name, "_", " ", -1)) + title := cases.Title(language.Und, cases.NoLower).String(strings.ReplaceAll(name, "_", " ")) return fmt.Sprintf("---\ntitle: \"%s\"\n---\n\n", title) } diff --git a/cmd/helm/repo_update.go b/cmd/helm/repo_update.go index 9dcc61d49..8a1169dd5 100644 --- a/cmd/helm/repo_update.go +++ b/cmd/helm/repo_update.go @@ -136,8 +136,7 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdate wg.Wait() if len(repoFailList) > 0 && failOnRepoUpdateFail { - return fmt.Errorf("Failed to update the following repositories: %s", - repoFailList) + return fmt.Errorf("Failed to update the following repositories: %s", repoFailList) //nolint:staticcheck } fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈") diff --git a/cmd/helm/template.go b/cmd/helm/template.go index ff6621a49..3c5278dbc 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -234,7 +234,7 @@ func writeToFile(outputDir string, name string, data string, append bool) error defer f.Close() - _, err = f.WriteString(fmt.Sprintf("---\n# Source: %s\n%s\n", name, data)) + _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", name, data) if err != nil { return err diff --git a/go.mod b/go.mod index fdc0e5ab3..04e1e90cf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module helm.sh/helm/v3 -go 1.24.0 +go 1.25.0 require ( github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 diff --git a/internal/test/test.go b/internal/test/test.go index e6821282c..e071d3160 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -92,5 +92,5 @@ func update(filename string, in []byte) error { } func normalize(in []byte) []byte { - return bytes.Replace(in, []byte("\r\n"), []byte("\n"), -1) + return bytes.ReplaceAll(in, []byte("\r\n"), []byte("\n")) } diff --git a/internal/third_party/dep/fs/fs.go b/internal/third_party/dep/fs/fs.go index d29bb5f87..7cbe8af84 100644 --- a/internal/third_party/dep/fs/fs.go +++ b/internal/third_party/dep/fs/fs.go @@ -172,28 +172,28 @@ func copyFile(src, dst string) (err error) { in, err := os.Open(src) if err != nil { - return + return //nolint:nakedret } defer in.Close() out, err := os.Create(dst) if err != nil { - return + return //nolint:nakedret } if _, err = io.Copy(out, in); err != nil { out.Close() - return + return //nolint:nakedret } // Check for write errors on Close if err = out.Close(); err != nil { - return + return //nolint:nakedret } si, err := os.Stat(src) if err != nil { - return + return //nolint:nakedret } // Temporary fix for Go < 1.9 @@ -205,7 +205,7 @@ func copyFile(src, dst string) (err error) { } err = os.Chmod(dst, si.Mode()) - return + return //nolint:nakedret } // cloneSymlink will create a new symlink that points to the resolved path of sl. diff --git a/internal/third_party/dep/fs/fs_test.go b/internal/third_party/dep/fs/fs_test.go index d42c3f110..22c59868c 100644 --- a/internal/third_party/dep/fs/fs_test.go +++ b/internal/third_party/dep/fs/fs_test.go @@ -33,17 +33,11 @@ package fs import ( "os" - "os/exec" "path/filepath" "runtime" - "sync" "testing" ) -var ( - mu sync.Mutex -) - func TestRenameWithFallback(t *testing.T) { dir := t.TempDir() @@ -360,19 +354,6 @@ func TestCopyFile(t *testing.T) { } } -func cleanUpDir(dir string) { - // NOTE(mattn): It seems that sometimes git.exe is not dead - // when cleanUpDir() is called. But we do not know any way to wait for it. - if runtime.GOOS == "windows" { - mu.Lock() - exec.Command(`taskkill`, `/F`, `/IM`, `git.exe`).Run() - mu.Unlock() - } - if dir != "" { - os.RemoveAll(dir) - } -} - func TestCopyFileSymlink(t *testing.T) { tempdir := t.TempDir() diff --git a/internal/third_party/k8s.io/kubernetes/deployment/util/deploymentutil.go b/internal/third_party/k8s.io/kubernetes/deployment/util/deploymentutil.go index ae62d0e6f..8f8b28fcb 100644 --- a/internal/third_party/k8s.io/kubernetes/deployment/util/deploymentutil.go +++ b/internal/third_party/k8s.io/kubernetes/deployment/util/deploymentutil.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package util //nolint:revive import ( "context" diff --git a/pkg/action/install.go b/pkg/action/install.go index f81f65749..f8f740005 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -619,7 +619,7 @@ func writeToFile(outputDir string, name string, data string, append bool) error defer f.Close() - _, err = f.WriteString(fmt.Sprintf("---\n# Source: %s\n%s\n", name, data)) + _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", name, data) if err != nil { return err diff --git a/pkg/engine/lookup_func.go b/pkg/engine/lookup_func.go index 75e85098d..3a859e8ff 100644 --- a/pkg/engine/lookup_func.go +++ b/pkg/engine/lookup_func.go @@ -38,7 +38,7 @@ type lookupFunc = func(apiversion string, resource string, namespace string, nam // // This function is considered deprecated, and will be renamed in Helm 4. It will no // longer be a public function. -func NewLookupFunction(config *rest.Config) lookupFunc { +func NewLookupFunction(config *rest.Config) lookupFunc { //nolint:revive return newLookupFunction(clientProviderFromConfig{config: config}) } diff --git a/pkg/registry/utils_test.go b/pkg/registry/utils_test.go index c47c8587d..7ed7c0a81 100644 --- a/pkg/registry/utils_test.go +++ b/pkg/registry/utils_test.go @@ -186,8 +186,7 @@ func initCompromisedRegistryTestServer() string { w.WriteHeader(200) // layers[0] is the blob []byte("a") - w.Write([]byte( - fmt.Sprintf(`{ "schemaVersion": 2, "config": { + fmt.Fprintf(w, `{ "schemaVersion": 2, "config": { "mediaType": "%s", "digest": "sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133", "size": 181 @@ -199,7 +198,7 @@ func initCompromisedRegistryTestServer() string { "size": 1 } ] -}`, ConfigMediaType, ChartLayerMediaType))) +}`, ConfigMediaType, ChartLayerMediaType) } else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133" { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) diff --git a/pkg/time/time.go b/pkg/time/time.go index 1abe8ae3d..678e368dd 100644 --- a/pkg/time/time.go +++ b/pkg/time/time.go @@ -19,7 +19,7 @@ limitations under the License. // where the serializer doesn't omit an empty value for time: // https://github.com/golang/go/issues/11939. As such, this can be removed if a // proposal is ever accepted for Go -package time +package time //nolint:revive import ( "bytes" diff --git a/pkg/time/time_test.go b/pkg/time/time_test.go index 20f0f8e29..5cced08dd 100644 --- a/pkg/time/time_test.go +++ b/pkg/time/time_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package time +package time //nolint:revive import ( "encoding/json"