chore(pkg): enable perfsprint linter

#### Description

enable perfsprint linter in pkg/action

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

@ -257,9 +257,9 @@ func (cfg *Configuration) outputLogsByPolicy(h *release.Hook, releaseNamespace s
} }
switch h.Kind { switch h.Kind {
case "Job": case "Job":
return cfg.outputContainerLogsForListOptions(namespace, metav1.ListOptions{LabelSelector: fmt.Sprintf("job-name=%s", h.Name)}) return cfg.outputContainerLogsForListOptions(namespace, metav1.ListOptions{LabelSelector: "job-name=" + h.Name})
case "Pod": case "Pod":
return cfg.outputContainerLogsForListOptions(namespace, metav1.ListOptions{FieldSelector: fmt.Sprintf("metadata.name=%s", h.Name)}) return cfg.outputContainerLogsForListOptions(namespace, metav1.ListOptions{FieldSelector: "metadata.name=" + h.Name})
default: default:
return nil return nil
} }

@ -17,6 +17,7 @@ limitations under the License.
package action package action
import ( import (
"errors"
"fmt" "fmt"
"maps" "maps"
@ -226,7 +227,7 @@ func validateNameAndGenerateName(info *resource.Info) (bool, error) {
} }
if info.Name != "" && accessor.GetGenerateName() != "" { if info.Name != "" && accessor.GetGenerateName() != "" {
return true, fmt.Errorf("metadata.name and metadata.generateName cannot both be set") return true, errors.New("metadata.name and metadata.generateName cannot both be set")
} }
return false, nil return false, nil

@ -17,7 +17,6 @@ package chart
import ( import (
"errors" "errors"
"fmt"
"log/slog" "log/slog"
"reflect" "reflect"
"strings" "strings"
@ -192,7 +191,7 @@ func structToMap(obj any) (map[string]any, error) {
// Check if the input is a struct // Check if the input is a struct
if objValue.Kind() != reflect.Struct { if objValue.Kind() != reflect.Struct {
return nil, fmt.Errorf("input must be a struct or a pointer to a struct") return nil, errors.New("input must be a struct or a pointer to a struct")
} }
result := make(map[string]any) result := make(map[string]any)

@ -18,6 +18,7 @@ package output
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
@ -50,7 +51,7 @@ func FormatsWithDesc() map[string]string {
} }
// ErrInvalidFormatType is returned when an unsupported format type is used // ErrInvalidFormatType is returned when an unsupported format type is used
var ErrInvalidFormatType = fmt.Errorf("invalid format type") var ErrInvalidFormatType = errors.New("invalid format type")
// String returns the string representation of the Format // String returns the string representation of the Format
func (o Format) String() string { func (o Format) String() string {

@ -19,7 +19,6 @@ package values
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -265,7 +264,7 @@ func TestReadFileErrorMessages(t *testing.T) {
{ {
name: "getter error with message", name: "getter error with message",
filePath: "http://example.com/file", filePath: "http://example.com/file",
providers: getter.Providers{mockProvider([]string{"http"}, nil, fmt.Errorf("connection refused"))}, providers: getter.Providers{mockProvider([]string{"http"}, nil, errors.New("connection refused"))},
wantErr: "connection refused", wantErr: "connection refused",
}, },
} }

@ -16,8 +16,8 @@ limitations under the License.
package require package require
import ( import (
"fmt"
"io" "io"
"strconv"
"strings" "strings"
"testing" "testing"
@ -65,7 +65,7 @@ type testCase struct {
func runTestCases(t *testing.T, testCases []testCase) { func runTestCases(t *testing.T, testCases []testCase) {
t.Helper() t.Helper()
for i, tc := range testCases { for i, tc := range testCases {
t.Run(fmt.Sprint(i), func(t *testing.T) { t.Run(strconv.Itoa(i), func(t *testing.T) {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "root", Use: "root",
Run: func(*cobra.Command, []string) {}, Run: func(*cobra.Command, []string) {},

@ -17,6 +17,7 @@ package downloader
import ( import (
"crypto/sha256" "crypto/sha256"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -85,5 +86,5 @@ func (c *DiskCache) Put(key [sha256.Size]byte, data io.Reader, cacheType string)
// fileName generates the filename in a structured manner where the first part is the // fileName generates the filename in a structured manner where the first part is the
// directory and the full hash is the filename. // directory and the full hash is the filename.
func (c *DiskCache) fileName(id [sha256.Size]byte, cacheType string) string { func (c *DiskCache) fileName(id [sha256.Size]byte, cacheType string) string {
return filepath.Join(c.Root, fmt.Sprintf("%02x", id[0]), fmt.Sprintf("%x", id)+cacheType) return filepath.Join(c.Root, fmt.Sprintf("%02x", id[0]), hex.EncodeToString(id[:])+cacheType)
} }

@ -17,7 +17,7 @@ package provenance
import ( import (
"crypto" "crypto"
"fmt" "errors"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
@ -330,7 +330,7 @@ func (s failSigner) Public() crypto.PublicKey {
} }
func (s failSigner) Sign(_ io.Reader, _ []byte, _ crypto.SignerOpts) ([]byte, error) { func (s failSigner) Sign(_ io.Reader, _ []byte, _ crypto.SignerOpts) ([]byte, error) {
return nil, fmt.Errorf("always fails") return nil, errors.New("always fails")
} }
func TestClearSignError(t *testing.T) { func TestClearSignError(t *testing.T) {

@ -76,7 +76,7 @@ func (pusher *OCIPusher) push(chartRef, href string) error {
} }
var pushOpts []registry.PushOption var pushOpts []registry.PushOption
provRef := fmt.Sprintf("%s.prov", chartRef) provRef := chartRef + ".prov"
if _, err := os.Stat(provRef); err == nil { if _, err := os.Stat(provRef); err == nil {
provBytes, err := os.ReadFile(provRef) provBytes, err := os.ReadFile(provRef)
if err != nil { if err != nil {
@ -86,7 +86,7 @@ func (pusher *OCIPusher) push(chartRef, href string) error {
} }
ref := fmt.Sprintf("%s:%s", ref := fmt.Sprintf("%s:%s",
path.Join(strings.TrimPrefix(href, fmt.Sprintf("%s://", registry.OCIScheme)), meta.Metadata.Name), path.Join(strings.TrimPrefix(href, registry.OCIScheme+"://"), meta.Metadata.Name),
meta.Metadata.Version) meta.Metadata.Version)
// The time the chart was "created" is semantically the time the chart archive file was last written(modified) // The time the chart was "created" is semantically the time the chart archive file was last written(modified)

@ -21,7 +21,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -611,7 +610,7 @@ func TestIgnoreSkippableChartValidationError(t *testing.T) {
Input: nil, Input: nil,
}, },
"generic_error": { "generic_error": {
Input: fmt.Errorf("foo"), Input: errors.New("foo"),
}, },
"non_skipped_validation_error": { "non_skipped_validation_error": {
Input: chart.ValidationError("chart.metadata.type must be application or library"), Input: chart.ValidationError("chart.metadata.type must be application or library"),

Loading…
Cancel
Save