chore(internal): enable perfsprint linter

#### Description

enable perfsprint linter in internal/plugin/installer

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/31870/head
Matthieu MOREL 7 months ago
parent bd334848b4
commit 9409226e15

@ -17,6 +17,7 @@ limitations under the License.
package rules package rules
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -47,7 +48,7 @@ func ValuesWithOverrides(linter *support.Linter, valueOverrides map[string]any,
func validateValuesFileExistence(valuesPath string) error { func validateValuesFileExistence(valuesPath string) error {
_, err := os.Stat(valuesPath) _, err := os.Stat(valuesPath)
if err != nil { if err != nil {
return fmt.Errorf("file does not exist") return errors.New("file does not exist")
} }
return nil return nil
} }

@ -21,8 +21,8 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"crypto/sha256" "crypto/sha256"
"encoding/hex"
"errors" "errors"
"fmt"
"io" "io"
"os" "os"
"path" "path"
@ -353,5 +353,5 @@ func sha256Sum(filePath string) (string, error) {
return "", err return "", err
} }
return fmt.Sprintf("%x", h.Sum(nil)), nil return hex.EncodeToString(h.Sum(nil)), nil
} }

@ -150,7 +150,7 @@ func TestHTTPInstallerNonExistentVersion(t *testing.T) {
// inject fake http client responding with error // inject fake http client responding with error
httpInstaller.getter = &TestHTTPGetter{ httpInstaller.getter = &TestHTTPGetter{
MockError: fmt.Errorf("failed to download plugin for some reason"), MockError: errors.New("failed to download plugin for some reason"),
} }
// attempt to install the plugin // attempt to install the plugin

@ -188,7 +188,7 @@ func (i *LocalInstaller) SupportsVerification() bool {
// GetVerificationData loads plugin and provenance data from local files for verification // GetVerificationData loads plugin and provenance data from local files for verification
func (i *LocalInstaller) GetVerificationData() (archiveData, provData []byte, filename string, err error) { func (i *LocalInstaller) GetVerificationData() (archiveData, provData []byte, filename string, err error) {
if !i.SupportsVerification() { if !i.SupportsVerification() {
return nil, nil, "", fmt.Errorf("verification not supported for directories") return nil, nil, "", errors.New("verification not supported for directories")
} }
// Read and cache the plugin archive file // Read and cache the plugin archive file

@ -130,7 +130,7 @@ func (i *OCIInstaller) Install() error {
// Check if this is a gzip compressed file // Check if this is a gzip compressed file
if len(i.pluginData) < 2 || i.pluginData[0] != 0x1f || i.pluginData[1] != 0x8b { if len(i.pluginData) < 2 || i.pluginData[0] != 0x1f || i.pluginData[1] != 0x8b {
return fmt.Errorf("plugin data is not a gzip compressed archive") return errors.New("plugin data is not a gzip compressed archive")
} }
// Create cache directory // Create cache directory

@ -82,7 +82,7 @@ command: "$HELM_PLUGIN_DIR/bin/%s"
// Add executable // Add executable
execContent := fmt.Sprintf("#!/bin/sh\necho '%s test plugin'", pluginName) execContent := fmt.Sprintf("#!/bin/sh\necho '%s test plugin'", pluginName)
execHeader := &tar.Header{ execHeader := &tar.Header{
Name: fmt.Sprintf("bin/%s", pluginName), Name: "bin/" + pluginName,
Mode: 0755, Mode: 0755,
Size: int64(len(execContent)), Size: int64(len(execContent)),
Typeflag: tar.TypeReg, Typeflag: tar.TypeReg,

@ -17,7 +17,6 @@ package plugin
import ( import (
"bytes" "bytes"
"fmt"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -71,7 +70,7 @@ func TestLoadDir(t *testing.T) {
} }
return Metadata{ return Metadata{
APIVersion: apiVersion, APIVersion: apiVersion,
Name: fmt.Sprintf("hello-%s", apiVersion), Name: "hello-" + apiVersion,
Version: "0.1.0", Version: "0.1.0",
Type: "cli/v1", Type: "cli/v1",
Runtime: "subprocess", Runtime: "subprocess",

@ -24,6 +24,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"slices" "slices"
"strconv"
"helm.sh/helm/v4/internal/plugin/schema" "helm.sh/helm/v4/internal/plugin/schema"
) )
@ -63,7 +64,7 @@ func (r *SubprocessPluginRuntime) runGetter(input *Input) (*Output, error) {
env["HELM_PLUGIN_DIR"] = r.pluginDir env["HELM_PLUGIN_DIR"] = r.pluginDir
env["HELM_PLUGIN_USERNAME"] = msg.Options.Username env["HELM_PLUGIN_USERNAME"] = msg.Options.Username
env["HELM_PLUGIN_PASSWORD"] = msg.Options.Password env["HELM_PLUGIN_PASSWORD"] = msg.Options.Password
env["HELM_PLUGIN_PASS_CREDENTIALS_ALL"] = fmt.Sprintf("%t", msg.Options.PassCredentialsAll) env["HELM_PLUGIN_PASS_CREDENTIALS_ALL"] = strconv.FormatBool(msg.Options.PassCredentialsAll)
command, args, err := PrepareCommands(d.PlatformCommand, false, []string{}, env) command, args, err := PrepareCommands(d.PlatformCommand, false, []string{}, env)
if err != nil { if err != nil {

@ -14,6 +14,7 @@
package schema package schema
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
) )
@ -55,7 +56,7 @@ type ConfigGetterV1 struct {
func (c *ConfigGetterV1) Validate() error { func (c *ConfigGetterV1) Validate() error {
if len(c.Protocols) == 0 { if len(c.Protocols) == 0 {
return fmt.Errorf("getter has no protocols") return errors.New("getter has no protocols")
} }
for i, protocol := range c.Protocols { for i, protocol := range c.Protocols {
if protocol == "" { if protocol == "" {

@ -149,7 +149,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
} else { } else {
// Retrieve list of tags for repository // Retrieve list of tags for repository
ref := fmt.Sprintf("%s/%s", strings.TrimPrefix(d.Repository, fmt.Sprintf("%s://", registry.OCIScheme)), d.Name) ref := fmt.Sprintf("%s/%s", strings.TrimPrefix(d.Repository, registry.OCIScheme+"://"), d.Name)
tags, err := r.registryClient.Tags(ref) tags, err := r.registryClient.Tags(ref)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not retrieve list of tags for repository %s: %w", d.Repository, err) return nil, fmt.Errorf("could not retrieve list of tags for repository %s: %w", d.Repository, err)

Loading…
Cancel
Save