chore(internal): enable perfsprint linter (#31871)

#### Description

enable perfsprint linter in internal/plugin

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/31886/head
Matthieu MOREL 7 months ago committed by GitHub
parent d888ca7787
commit d4f6193a7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -19,7 +19,6 @@ package rules
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"io" "io"
"io/fs" "io/fs"
"os" "os"
@ -102,14 +101,14 @@ func validateCrdsDir(crdsPath string) error {
func validateCrdAPIVersion(obj *k8sYamlStruct) error { func validateCrdAPIVersion(obj *k8sYamlStruct) error {
if !strings.HasPrefix(obj.APIVersion, "apiextensions.k8s.io") { if !strings.HasPrefix(obj.APIVersion, "apiextensions.k8s.io") {
return fmt.Errorf("apiVersion is not in 'apiextensions.k8s.io'") return errors.New("apiVersion is not in 'apiextensions.k8s.io'")
} }
return nil return nil
} }
func validateCrdKind(obj *k8sYamlStruct) error { func validateCrdKind(obj *k8sYamlStruct) error {
if obj.Kind != "CustomResourceDefinition" { if obj.Kind != "CustomResourceDefinition" {
return fmt.Errorf("object kind is not 'CustomResourceDefinition'") return errors.New("object kind is not 'CustomResourceDefinition'")
} }
return nil return nil
} }

@ -17,6 +17,7 @@ package installer // import "helm.sh/helm/v4/internal/plugin/installer"
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"os" "os"
@ -143,7 +144,7 @@ func (i *HTTPInstaller) Install() error {
// Update updates a local repository // Update updates a local repository
// Not implemented for now since tarball most likely will be packaged by version // Not implemented for now since tarball most likely will be packaged by version
func (i *HTTPInstaller) Update() error { func (i *HTTPInstaller) Update() error {
return fmt.Errorf("method Update() not implemented for HttpInstaller") return errors.New("method Update() not implemented for HttpInstaller")
} }
// Path is overridden because we want to join on the plugin name not the file name // Path is overridden because we want to join on the plugin name not the file name
@ -163,7 +164,7 @@ func (i *HTTPInstaller) SupportsVerification() bool {
// GetVerificationData returns cached plugin and provenance data for verification // GetVerificationData returns cached plugin and provenance data for verification
func (i *HTTPInstaller) GetVerificationData() (archiveData, provData []byte, filename string, err error) { func (i *HTTPInstaller) GetVerificationData() (archiveData, provData []byte, filename string, err error) {
if !i.SupportsVerification() { if !i.SupportsVerification() {
return nil, nil, "", fmt.Errorf("verification not supported for this source") return nil, nil, "", errors.New("verification not supported for this source")
} }
// Download plugin data once and cache it // Download plugin data once and cache it

@ -87,7 +87,7 @@ func InstallWithOptions(i Installer, opts Options) (*VerificationResult, error)
if opts.Verify { if opts.Verify {
verifier, ok := i.(Verifier) verifier, ok := i.(Verifier)
if !ok || !verifier.SupportsVerification() { if !ok || !verifier.SupportsVerification() {
return nil, fmt.Errorf("--verify is only supported for plugin tarballs (.tgz files)") return nil, errors.New("--verify is only supported for plugin tarballs (.tgz files)")
} }
// Get verification data (works for both memory and file-based installers) // Get verification data (works for both memory and file-based installers)
@ -137,7 +137,7 @@ func Update(i Installer) error {
// NewForSource determines the correct Installer for the given source. // NewForSource determines the correct Installer for the given source.
func NewForSource(source, version string) (installer Installer, err error) { func NewForSource(source, version string) (installer Installer, err error) {
if strings.HasPrefix(source, fmt.Sprintf("%s://", registry.OCIScheme)) { if strings.HasPrefix(source, registry.OCIScheme+"://") {
// Source is an OCI registry reference // Source is an OCI registry reference
installer, err = NewOCIInstaller(source) installer, err = NewOCIInstaller(source)
} else if isLocalReference(source) { } else if isLocalReference(source) {

@ -58,23 +58,23 @@ func (m Metadata) Validate() error {
} }
if m.APIVersion == "" { if m.APIVersion == "" {
errs = append(errs, fmt.Errorf("empty APIVersion")) errs = append(errs, errors.New("empty APIVersion"))
} }
if m.Type == "" { if m.Type == "" {
errs = append(errs, fmt.Errorf("empty type field")) errs = append(errs, errors.New("empty type field"))
} }
if m.Runtime == "" { if m.Runtime == "" {
errs = append(errs, fmt.Errorf("empty runtime field")) errs = append(errs, errors.New("empty runtime field"))
} }
if m.Config == nil { if m.Config == nil {
errs = append(errs, fmt.Errorf("missing config field")) errs = append(errs, errors.New("missing config field"))
} }
if m.RuntimeConfig == nil { if m.RuntimeConfig == nil {
errs = append(errs, fmt.Errorf("missing runtimeConfig field")) errs = append(errs, errors.New("missing runtimeConfig field"))
} }
// Validate the config itself // Validate the config itself

@ -16,6 +16,7 @@ limitations under the License.
package plugin package plugin
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"unicode" "unicode"
@ -74,11 +75,11 @@ func (m *MetadataLegacy) Validate() error {
m.Usage = sanitizeString(m.Usage) m.Usage = sanitizeString(m.Usage)
if len(m.PlatformCommand) > 0 && len(m.Command) > 0 { if len(m.PlatformCommand) > 0 && len(m.Command) > 0 {
return fmt.Errorf("both platformCommand and command are set") return errors.New("both platformCommand and command are set")
} }
if len(m.PlatformHooks) > 0 && len(m.Hooks) > 0 { if len(m.PlatformHooks) > 0 && len(m.Hooks) > 0 {
return fmt.Errorf("both platformHooks and hooks are set") return errors.New("both platformHooks and hooks are set")
} }
// Validate downloader plugins // Validate downloader plugins

@ -16,6 +16,7 @@ limitations under the License.
package plugin package plugin
import ( import (
"errors"
"fmt" "fmt"
) )
@ -48,7 +49,7 @@ type MetadataV1 struct {
func (m *MetadataV1) Validate() error { func (m *MetadataV1) Validate() error {
if !validPluginName.MatchString(m.Name) { if !validPluginName.MatchString(m.Name) {
return fmt.Errorf("invalid plugin `name`") return errors.New("invalid plugin `name`")
} }
if m.APIVersion != "v1" { if m.APIVersion != "v1" {
@ -56,11 +57,11 @@ func (m *MetadataV1) Validate() error {
} }
if m.Type == "" { if m.Type == "" {
return fmt.Errorf("`type` missing") return errors.New("`type` missing")
} }
if m.Runtime == "" { if m.Runtime == "" {
return fmt.Errorf("`runtime` missing") return errors.New("`runtime` missing")
} }
return nil return nil

@ -117,8 +117,8 @@ func (r *SubprocessPluginRuntime) InvokeWithEnv(main string, argv []string, env
cmd.Env = slices.Clone(os.Environ()) cmd.Env = slices.Clone(os.Environ())
cmd.Env = append( cmd.Env = append(
cmd.Env, cmd.Env,
fmt.Sprintf("HELM_PLUGIN_NAME=%s", r.metadata.Name), "HELM_PLUGIN_NAME="+r.metadata.Name,
fmt.Sprintf("HELM_PLUGIN_DIR=%s", r.pluginDir)) "HELM_PLUGIN_DIR="+r.pluginDir)
cmd.Env = append(cmd.Env, env...) cmd.Env = append(cmd.Env, env...)
cmd.Stdin = stdin cmd.Stdin = stdin

@ -16,7 +16,7 @@ limitations under the License.
package plugin package plugin
import ( import (
"fmt" "errors"
"os" "os"
"runtime" "runtime"
"strings" "strings"
@ -80,7 +80,7 @@ func getPlatformCommand(cmds []PlatformCommand) ([]string, []string) {
func PrepareCommands(cmds []PlatformCommand, expandArgs bool, extraArgs []string, env map[string]string) (string, []string, error) { func PrepareCommands(cmds []PlatformCommand, expandArgs bool, extraArgs []string, env map[string]string) (string, []string, error) {
cmdParts, args := getPlatformCommand(cmds) cmdParts, args := getPlatformCommand(cmds)
if len(cmdParts) == 0 || cmdParts[0] == "" { if len(cmdParts) == 0 || cmdParts[0] == "" {
return "", nil, fmt.Errorf("no plugin command is applicable") return "", nil, errors.New("no plugin command is applicable")
} }
envMappingFunc := func(key string) string { envMappingFunc := func(key string) string {
return env[key] return env[key]

@ -17,8 +17,8 @@ limitations under the License.
package v2 package v2
import ( import (
"fmt"
"math/rand" "math/rand"
"strconv"
"time" "time"
v3 "helm.sh/helm/v4/internal/chart/v3" v3 "helm.sh/helm/v4/internal/chart/v3"
@ -57,7 +57,7 @@ func Mock(opts *MockReleaseOptions) *Release {
name := opts.Name name := opts.Name
if name == "" { if name == "" {
name = "testrelease-" + fmt.Sprint(rand.Intn(100)) name = "testrelease-" + strconv.Itoa(rand.Intn(100))
} }
version := 1 version := 1

@ -17,7 +17,7 @@ limitations under the License.
package version package version
import ( import (
"fmt" "errors"
"runtime/debug" "runtime/debug"
"slices" "slices"
@ -27,7 +27,7 @@ import (
func K8sIOClientGoModVersion() (string, error) { func K8sIOClientGoModVersion() (string, error) {
info, ok := debug.ReadBuildInfo() info, ok := debug.ReadBuildInfo()
if !ok { if !ok {
return "", fmt.Errorf("failed to read build info") return "", errors.New("failed to read build info")
} }
idx := slices.IndexFunc(info.Deps, func(m *debug.Module) bool { idx := slices.IndexFunc(info.Deps, func(m *debug.Module) bool {
@ -35,7 +35,7 @@ func K8sIOClientGoModVersion() (string, error) {
}) })
if idx == -1 { if idx == -1 {
return "", fmt.Errorf("k8s.io/client-go not found in build info") return "", errors.New("k8s.io/client-go not found in build info")
} }
m := info.Deps[idx] m := info.Deps[idx]

Loading…
Cancel
Save