From fb9101ad5921af96f05ffb8a1856e3590bed4b5c Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Wed, 14 Aug 2024 14:13:44 +0200 Subject: [PATCH] fix: linter warnings in new Golang CI version (#2883) Signed-off-by: Philip Laine --- .golangci.yaml | 1 + src/extensions/bigbang/test/bigbang_test.go | 2 +- src/pkg/lint/validate.go | 16 ++++++++-------- src/pkg/packager/prepare.go | 3 ++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 58aaa823f9..6f46337df5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -23,6 +23,7 @@ linters-settings: - shadow - fieldalignment - unusedwrite + - printf nolintlint: require-specific: true goheader: diff --git a/src/extensions/bigbang/test/bigbang_test.go b/src/extensions/bigbang/test/bigbang_test.go index f8bf1cd448..16bf87bdbc 100644 --- a/src/extensions/bigbang/test/bigbang_test.go +++ b/src/extensions/bigbang/test/bigbang_test.go @@ -47,7 +47,7 @@ func TestMain(m *testing.M) { zarf = fmt.Sprintf("./%s", test.GetCLIName()) // Run the tests - m.Run() + os.Exit(m.Run()) } func TestReleases(t *testing.T) { diff --git a/src/pkg/lint/validate.go b/src/pkg/lint/validate.go index 0cba4efe15..2de0ba8e91 100644 --- a/src/pkg/lint/validate.go +++ b/src/pkg/lint/validate.go @@ -71,7 +71,7 @@ const ( func ValidatePackage(pkg v1alpha1.ZarfPackage) error { var err error if pkg.Kind == v1alpha1.ZarfInitConfig && pkg.Metadata.YOLO { - err = errors.Join(err, fmt.Errorf(PkgValidateErrInitNoYOLO)) + err = errors.Join(err, errors.New(PkgValidateErrInitNoYOLO)) } for _, constant := range pkg.Constants { if varErr := constant.Validate(); varErr != nil { @@ -84,16 +84,16 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error { if pkg.Metadata.YOLO { for _, component := range pkg.Components { if len(component.Images) > 0 { - err = errors.Join(err, fmt.Errorf(PkgValidateErrYOLONoOCI)) + err = errors.Join(err, errors.New(PkgValidateErrYOLONoOCI)) } if len(component.Repos) > 0 { - err = errors.Join(err, fmt.Errorf(PkgValidateErrYOLONoGit)) + err = errors.Join(err, errors.New(PkgValidateErrYOLONoGit)) } if component.Only.Cluster.Architecture != "" { - err = errors.Join(err, fmt.Errorf(PkgValidateErrYOLONoArch)) + err = errors.Join(err, errors.New(PkgValidateErrYOLONoArch)) } if len(component.Only.Cluster.Distros) > 0 { - err = errors.Join(err, fmt.Errorf(PkgValidateErrYOLONoDistro)) + err = errors.Join(err, errors.New(PkgValidateErrYOLONoDistro)) } } } @@ -220,12 +220,12 @@ func validateAction(action v1alpha1.ZarfComponentAction) error { // Validate only cluster or network, not both if action.Wait.Cluster != nil && action.Wait.Network != nil { - err = errors.Join(err, fmt.Errorf(PkgValidateErrActionClusterNetwork)) + err = errors.Join(err, errors.New(PkgValidateErrActionClusterNetwork)) } // Validate at least one of cluster or network if action.Wait.Cluster == nil && action.Wait.Network == nil { - err = errors.Join(err, fmt.Errorf(PkgValidateErrActionClusterNetwork)) + err = errors.Join(err, errors.New(PkgValidateErrActionClusterNetwork)) } } @@ -243,7 +243,7 @@ func validateReleaseName(chartName, releaseName string) (err error) { // Check if the final releaseName is empty and return an error if so if releaseName == "" { - err = fmt.Errorf(errChartReleaseNameEmpty) + err = errors.New(errChartReleaseNameEmpty) return } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 214258634a..0c1ef19f30 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -6,6 +6,7 @@ package packager import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -364,7 +365,7 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, } errMsg += fmt.Sprintf("the following images errored on cosign lookups: %s", erroredCosignLookups) } - return imagesMap, fmt.Errorf(errMsg) + return imagesMap, errors.New(errMsg) } return imagesMap, nil