From 0c95ae46c384ca5d7353e711494f2e5f491af2a6 Mon Sep 17 00:00:00 2001 From: Martin Mulholland Date: Thu, 30 Sep 2021 15:29:05 -0400 Subject: [PATCH] test(linter): switch from golint to revive and fix lint errors Signed-off-by: Martin Mulholland --- .golangci.yml | 2 +- cmd/helm/completion_test.go | 4 +-- cmd/helm/install.go | 2 +- cmd/helm/load_plugins.go | 2 +- cmd/helm/repo_update.go | 4 +-- cmd/helm/root_unix.go | 1 + cmd/helm/root_unix_test.go | 1 + cmd/helm/upgrade.go | 2 +- internal/experimental/registry/client.go | 16 +++------ .../experimental/uploader/chart_uploader.go | 2 +- pkg/chartutil/validate_name.go | 8 ++--- pkg/cli/environment_test.go | 36 +++++++++---------- pkg/helmpath/home_unix_test.go | 1 + pkg/helmpath/lazypath_darwin.go | 1 + pkg/helmpath/lazypath_darwin_test.go | 1 + 15 files changed, 41 insertions(+), 42 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5c2445711..2807ede34 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,12 +8,12 @@ linters: - dupl - gofmt - goimports - - golint - gosimple - govet - ineffassign - misspell - nakedret + - revive - structcheck - unused - varcheck diff --git a/cmd/helm/completion_test.go b/cmd/helm/completion_test.go index 6d53616d0..1143d6445 100644 --- a/cmd/helm/completion_test.go +++ b/cmd/helm/completion_test.go @@ -47,10 +47,10 @@ func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) { } if !strings.Contains(out, "ShellCompDirectiveNoFileComp") != shouldBePerformed { if shouldBePerformed { - t.Error(fmt.Sprintf("Unexpected directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)) + t.Errorf("Unexpected directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName) } else { - t.Error(fmt.Sprintf("Did not receive directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)) + t.Errorf("Did not receive directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName) } t.Log(out) } diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 8b468d2f5..75ecbe3af 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -254,7 +254,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options ctx, cancel := context.WithCancel(ctx) // Handle SIGTERM - cSignal := make(chan os.Signal) + cSignal := make(chan os.Signal, 1) signal.Notify(cSignal, os.Interrupt, syscall.SIGTERM) go func() { <-cSignal diff --git a/cmd/helm/load_plugins.go b/cmd/helm/load_plugins.go index 70002b0b0..a97d49a93 100644 --- a/cmd/helm/load_plugins.go +++ b/cmd/helm/load_plugins.go @@ -313,7 +313,7 @@ func loadFile(path string) (*pluginCommand, error) { cmds := new(pluginCommand) b, err := ioutil.ReadFile(path) if err != nil { - return cmds, errors.New(fmt.Sprintf("File (%s) not provided by plugin. No plugin auto-completion possible.", path)) + return cmds, fmt.Errorf("file (%s) not provided by plugin. No plugin auto-completion possible", path) } err = yaml.Unmarshal(b, cmds) diff --git a/cmd/helm/repo_update.go b/cmd/helm/repo_update.go index ae09f9195..27661674c 100644 --- a/cmd/helm/repo_update.go +++ b/cmd/helm/repo_update.go @@ -133,8 +133,8 @@ func updateCharts(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdate wg.Wait() if len(repoFailList) > 0 && failOnRepoUpdateFail { - return errors.New(fmt.Sprintf("Failed to update the following repositories: %s", - repoFailList)) + return fmt.Errorf("Failed to update the following repositories: %s", + repoFailList) } fmt.Fprintln(out, "Update Complete. ⎈Happy Helming!⎈") diff --git a/cmd/helm/root_unix.go b/cmd/helm/root_unix.go index 3df801e4c..47be08b95 100644 --- a/cmd/helm/root_unix.go +++ b/cmd/helm/root_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows /* diff --git a/cmd/helm/root_unix_test.go b/cmd/helm/root_unix_test.go index c62776c2a..36abc0184 100644 --- a/cmd/helm/root_unix_test.go +++ b/cmd/helm/root_unix_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows /* diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index a8ff93880..d45775fe0 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -187,7 +187,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { ctx, cancel := context.WithCancel(ctx) // Handle SIGTERM - cSignal := make(chan os.Signal) + cSignal := make(chan os.Signal, 1) signal.Notify(cSignal, os.Interrupt, syscall.SIGTERM) go func() { <-cSignal diff --git a/internal/experimental/registry/client.go b/internal/experimental/registry/client.go index 2e8b089aa..4f2dcb61b 100644 --- a/internal/experimental/registry/client.go +++ b/internal/experimental/registry/client.go @@ -240,9 +240,8 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) { } numDescriptors := len(descriptors) if numDescriptors < minNumDescriptors { - return nil, errors.New( - fmt.Sprintf("manifest does not contain minimum number of descriptors (%d), descriptors found: %d", - minNumDescriptors, numDescriptors)) + return nil, fmt.Errorf("manifest does not contain minimum number of descriptors (%d), descriptors found: %d", + minNumDescriptors, numDescriptors) } var configDescriptor *ocispec.Descriptor var chartDescriptor *ocispec.Descriptor @@ -259,22 +258,17 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) { } } if configDescriptor == nil { - return nil, errors.New( - fmt.Sprintf("could not load config with mediatype %s", ConfigMediaType)) + return nil, fmt.Errorf("could not load config with mediatype %s", ConfigMediaType) } if operation.withChart && chartDescriptor == nil { - return nil, errors.New( - fmt.Sprintf("manifest does not contain a layer with mediatype %s", - ChartLayerMediaType)) + return nil, fmt.Errorf("manifest does not contain a layer with mediatype %s", ChartLayerMediaType) } var provMissing bool if operation.withProv && provDescriptor == nil { if operation.ignoreMissingProv { provMissing = true } else { - return nil, errors.New( - fmt.Sprintf("manifest does not contain a layer with mediatype %s", - ProvLayerMediaType)) + return nil, fmt.Errorf("manifest does not contain a layer with mediatype %s", ProvLayerMediaType) } } result := &PullResult{ diff --git a/internal/experimental/uploader/chart_uploader.go b/internal/experimental/uploader/chart_uploader.go index 87a9d5772..00821d991 100644 --- a/internal/experimental/uploader/chart_uploader.go +++ b/internal/experimental/uploader/chart_uploader.go @@ -46,7 +46,7 @@ func (c *ChartUploader) UploadTo(ref, remote string) error { } if u.Scheme == "" { - return errors.New(fmt.Sprintf("scheme prefix missing from remote (e.g. \"%s://\")", registry.OCIScheme)) + return fmt.Errorf("scheme prefix missing from remote (e.g. \"%s://\")", registry.OCIScheme) } p, err := c.Pushers.ByScheme(u.Scheme) diff --git a/pkg/chartutil/validate_name.go b/pkg/chartutil/validate_name.go index d253731ec..393df7b7f 100644 --- a/pkg/chartutil/validate_name.go +++ b/pkg/chartutil/validate_name.go @@ -40,15 +40,15 @@ var ( errMissingName = errors.New("no name provided") // errInvalidName indicates that an invalid release name was provided - errInvalidName = errors.New(fmt.Sprintf( + errInvalidName = fmt.Errorf( "invalid release name, must match regex %s and the length must not be longer than 53", - validName.String())) + validName.String()) // errInvalidKubernetesName indicates that the name does not meet the Kubernetes // restrictions on metadata names. - errInvalidKubernetesName = errors.New(fmt.Sprintf( + errInvalidKubernetesName = fmt.Errorf( "invalid metadata name, must match regex %s and the length must not be longer than 253", - validName.String())) + validName.String()) ) const ( diff --git a/pkg/cli/environment_test.go b/pkg/cli/environment_test.go index 31ba7a237..bd8a81eac 100644 --- a/pkg/cli/environment_test.go +++ b/pkg/cli/environment_test.go @@ -37,9 +37,9 @@ func TestEnvSettings(t *testing.T) { ns, kcontext string debug bool maxhistory int - kAsUser string - kAsGroups []string - kCaFile string + asUser string + asGroups []string + caFile string }{ { name: "defaults", @@ -52,9 +52,9 @@ func TestEnvSettings(t *testing.T) { ns: "myns", debug: true, maxhistory: defaultMaxHistory, - kAsUser: "poro", - kAsGroups: []string{"admins", "teatime", "snackeaters"}, - kCaFile: "/tmp/ca.crt", + asUser: "poro", + asGroups: []string{"admins", "teatime", "snackeaters"}, + caFile: "/tmp/ca.crt", }, { name: "with envvars set", @@ -62,9 +62,9 @@ func TestEnvSettings(t *testing.T) { ns: "yourns", maxhistory: 5, debug: true, - kAsUser: "pikachu", - kAsGroups: []string{"operators", "snackeaters", "partyanimals"}, - kCaFile: "/tmp/ca.crt", + asUser: "pikachu", + asGroups: []string{"operators", "snackeaters", "partyanimals"}, + caFile: "/tmp/ca.crt", }, { name: "with flags and envvars set", @@ -73,9 +73,9 @@ func TestEnvSettings(t *testing.T) { ns: "myns", debug: true, maxhistory: 5, - kAsUser: "poro", - kAsGroups: []string{"admins", "teatime", "snackeaters"}, - kCaFile: "/my/ca.crt", + asUser: "poro", + asGroups: []string{"admins", "teatime", "snackeaters"}, + caFile: "/my/ca.crt", }, } @@ -105,14 +105,14 @@ func TestEnvSettings(t *testing.T) { if settings.MaxHistory != tt.maxhistory { t.Errorf("expected maxHistory %d, got %d", tt.maxhistory, settings.MaxHistory) } - if tt.kAsUser != settings.KubeAsUser { - t.Errorf("expected kAsUser %q, got %q", tt.kAsUser, settings.KubeAsUser) + if tt.asUser != settings.KubeAsUser { + t.Errorf("expected asUser %q, got %q", tt.asUser, settings.KubeAsUser) } - if !reflect.DeepEqual(tt.kAsGroups, settings.KubeAsGroups) { - t.Errorf("expected kAsGroups %+v, got %+v", len(tt.kAsGroups), len(settings.KubeAsGroups)) + if !reflect.DeepEqual(tt.asGroups, settings.KubeAsGroups) { + t.Errorf("expected asGroups %+v, got %+v", len(tt.asGroups), len(settings.KubeAsGroups)) } - if tt.kCaFile != settings.KubeCaFile { - t.Errorf("expected kCaFile %q, got %q", tt.kCaFile, settings.KubeCaFile) + if tt.caFile != settings.KubeCaFile { + t.Errorf("expected caFile %q, got %q", tt.caFile, settings.KubeCaFile) } }) } diff --git a/pkg/helmpath/home_unix_test.go b/pkg/helmpath/home_unix_test.go index 6a72152c4..b2a6b7a14 100644 --- a/pkg/helmpath/home_unix_test.go +++ b/pkg/helmpath/home_unix_test.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !windows // +build !windows package helmpath diff --git a/pkg/helmpath/lazypath_darwin.go b/pkg/helmpath/lazypath_darwin.go index e112b8337..80477abab 100644 --- a/pkg/helmpath/lazypath_darwin.go +++ b/pkg/helmpath/lazypath_darwin.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build darwin // +build darwin package helmpath diff --git a/pkg/helmpath/lazypath_darwin_test.go b/pkg/helmpath/lazypath_darwin_test.go index 9381a44e2..8c1c91e42 100644 --- a/pkg/helmpath/lazypath_darwin_test.go +++ b/pkg/helmpath/lazypath_darwin_test.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build darwin // +build darwin package helmpath