Skip to content

Commit

Permalink
chore: enable err-error and strconcat of perfsprint linter (#21267)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Dec 20, 2024
1 parent 12a4dab commit f245e8b
Show file tree
Hide file tree
Showing 85 changed files with 210 additions and 226 deletions.
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ linters-settings:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: false
err-error: true
# Optimizes `fmt.Errorf`.
errorf: false
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: true
# Optimizes into strings concatenation.
strconcat: false
strconcat: true
testifylint:
enable-all: true
disable:
Expand Down
4 changes: 2 additions & 2 deletions applicationset/generators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
params["metadata"] = meta
} else {
for key, value := range cluster.ObjectMeta.Annotations {
params[fmt.Sprintf("metadata.annotations.%s", key)] = value
params["metadata.annotations."+key] = value
}

for key, value := range cluster.ObjectMeta.Labels {
params[fmt.Sprintf("metadata.labels.%s", key)] = value
params["metadata.labels."+key] = value
}
}

Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/duck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A
}
params["values"].(map[string]string)[key] = value
} else {
params[fmt.Sprintf("values.%s", key)] = value
params["values."+key] = value
}
}

Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (g *ListGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.Appli
if !ok {
return nil, fmt.Errorf("error parsing value as string %w", err)
}
params[fmt.Sprintf("values.%s", k)] = value
params["values."+k] = value
}
} else {
v, ok := value.(string)
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/value_interpolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func appendTemplatedValues(values map[string]string, params map[string]interface
}
tmp["values"].(map[string]string)[key] = result
} else {
tmp[fmt.Sprintf("values.%s", key)] = result
tmp["values."+key] = result
}
}

Expand Down
3 changes: 1 addition & 2 deletions applicationset/services/plugin/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package plugin

import (
"fmt"
"strings"

"github.com/argoproj/argo-cd/v2/common"
Expand All @@ -12,7 +11,7 @@ func ParseSecretKey(key string) (secretName string, tokenKey string) {
if strings.Contains(key, ":") {
parts := strings.Split(key, ":")
secretName = parts[0][1:]
tokenKey = fmt.Sprintf("$%s", parts[1])
tokenKey = "$" + parts[1]
} else {
secretName = common.ArgoCDSecretName
tokenKey = key
Expand Down
6 changes: 3 additions & 3 deletions applicationset/services/scm_provider/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func (g *GiteaProvider) RepoHasPath(ctx context.Context, repo *Repository, path
if resp != nil && resp.StatusCode == http.StatusNotFound {
return false, nil
}
if fmt.Sprint(err) == "expect file, got directory" {
return true, nil
}
if err != nil {
if err.Error() == "expect file, got directory" {
return true, nil
}
return false, err
}
return true, nil
Expand Down
2 changes: 1 addition & 1 deletion applicationset/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (h *WebhookHandler) Handler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
status = http.StatusMethodNotAllowed
}
http.Error(w, fmt.Sprintf("Webhook processing failed: %s", html.EscapeString(err.Error())), status)
http.Error(w, "Webhook processing failed: "+html.EscapeString(err.Error()), status)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ func NewCommand() *cobra.Command {
// repository server, if strict TLS validation was requested.
if !repoServerPlaintext && repoServerStrictTLS {
pool, err := tls.LoadX509CertPool(
fmt.Sprintf("%s/controller/tls/tls.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
fmt.Sprintf("%s/controller/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/controller/tls/tls.crt",
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/controller/tls/ca.crt",
)
if err != nil {
log.Fatalf("%v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func NewCommand() *cobra.Command {

if !repoServerPlaintext && repoServerStrictTLS {
pool, err := tls.LoadX509CertPool(
fmt.Sprintf("%s/reposerver/tls/tls.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
fmt.Sprintf("%s/reposerver/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/reposerver/tls/tls.crt",
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/reposerver/tls/ca.crt",
)
errors.CheckError(err)
tlsConfig.Certificates = pool
Expand Down
4 changes: 2 additions & 2 deletions cmd/argocd-notification/commands/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func NewCommand() *cobra.Command {
}
if !tlsConfig.DisableTLS && tlsConfig.StrictValidation {
pool, err := tls.LoadX509CertPool(
fmt.Sprintf("%s/reposerver/tls/tls.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
fmt.Sprintf("%s/reposerver/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/reposerver/tls/tls.crt",
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/reposerver/tls/ca.crt",
)
if err != nil {
return fmt.Errorf("failed to load repo-server certificate pool: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions cmd/argocd-server/commands/argocd_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func NewCommand() *cobra.Command {
// repository server, if strict TLS validation was requested.
if !repoServerPlaintext && repoServerStrictTLS {
pool, err := tls.LoadX509CertPool(
fmt.Sprintf("%s/server/tls/tls.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
fmt.Sprintf("%s/server/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/server/tls/tls.crt",
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/server/tls/ca.crt",
)
if err != nil {
log.Fatalf("%v", err)
Expand All @@ -186,14 +186,14 @@ func NewCommand() *cobra.Command {

if !dexServerPlaintext && dexServerStrictTLS {
pool, err := tls.LoadX509CertPool(
fmt.Sprintf("%s/dex/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath) + "/dex/tls/ca.crt",
)
if err != nil {
log.Fatalf("%v", err)
}
dexTlsConfig.RootCAs = pool
cert, err := tls.LoadX509Cert(
fmt.Sprintf("%s/dex/tls/tls.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath) + "/dex/tls/tls.crt",
)
if err != nil {
log.Fatalf("%v", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func printAccountDetails(acc *accountpkg.Account) {
expiresAt := time.Unix(t.ExpiresAt, 0)
expiresAtFormatted = expiresAt.Format(time.RFC3339)
if expiresAt.Before(time.Now()) {
expiresAtFormatted = fmt.Sprintf("%s (expired)", expiresAtFormatted)
expiresAtFormatted = expiresAtFormatted + " (expired)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/admin/generatespec_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func getOutWriter(inline bool, filePath string) (io.Writer, io.Closer, error) {
return nil, nil, errors.New("The file path must be specified using flag '--file'")
}

err := os.Rename(filePath, fmt.Sprintf("%s.back", filePath))
err := os.Rename(filePath, filePath+".back")
if err != nil {
return nil, nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/argocd/commands/admin/generatespec_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package admin

import (
"bytes"
"fmt"
"os"
"testing"

Expand All @@ -25,15 +24,15 @@ func TestGetOutWriter_InlineOff(t *testing.T) {
func TestGetOutWriter_InlineOn(t *testing.T) {
tmpFile := t.TempDir()
defer func() {
_ = os.Remove(fmt.Sprintf("%s.back", tmpFile))
_ = os.Remove(tmpFile + ".back")
}()

out, closer, err := getOutWriter(true, tmpFile)
require.NoError(t, err)
defer io.Close(closer)

assert.Equal(t, tmpFile, out.(*os.File).Name())
_, err = os.Stat(fmt.Sprintf("%s.back", tmpFile))
_, err = os.Stat(tmpFile + ".back")
require.NoError(t, err, "Back file must be created")
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/argocd/commands/admin/notifications.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package admin

import (
"fmt"
"log"

"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -51,8 +50,8 @@ func NewNotificationsCommand() *cobra.Command {
}
if !tlsConfig.DisableTLS && tlsConfig.StrictValidation {
pool, err := tls.LoadX509CertPool(
fmt.Sprintf("%s/reposerver/tls/tls.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
fmt.Sprintf("%s/reposerver/tls/ca.crt", env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)),
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/reposerver/tls/tls.crt",
env.StringFromEnv(common.EnvAppConfigPath, common.DefaultAppConfigPath)+"/reposerver/tls/ca.crt",
)
if err != nil {
log.Fatalf("Failed to load tls certs: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/admin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var validatorsByGroup = map[string]settingValidator{
}
var summary string
if ssoProvider != "" {
summary = fmt.Sprintf("%s is configured", ssoProvider)
summary = ssoProvider + " is configured"
if general.URL == "" {
summary = summary + " ('url' field is missing)"
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/argocd/commands/admin/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package admin
import (
"bytes"
"context"
"fmt"
"io"
"os"
"testing"
Expand Down Expand Up @@ -270,7 +269,7 @@ func TestValidateSettingsCommand_NoErrors(t *testing.T) {

require.NoError(t, err)
for k := range validatorsByGroup {
assert.Contains(t, out, fmt.Sprintf("✅ %s", k))
assert.Contains(t, out, "✅ "+k)
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ func printAppSummaryTable(app *argoappv1.Application, appURL string, windows *ar
syncStatusStr := string(app.Status.Sync.Status)
switch app.Status.Sync.Status {
case argoappv1.SyncStatusCodeSynced:
syncStatusStr += fmt.Sprintf(" to %s", app.Spec.GetSource().TargetRevision)
syncStatusStr += " to " + app.Spec.GetSource().TargetRevision
case argoappv1.SyncStatusCodeOutOfSync:
syncStatusStr += fmt.Sprintf(" from %s", app.Spec.GetSource().TargetRevision)
syncStatusStr += " from " + app.Spec.GetSource().TargetRevision
}
if !git.IsCommitSHA(app.Spec.GetSource().TargetRevision) && !git.IsTruncatedCommitSHA(app.Spec.GetSource().TargetRevision) && len(app.Status.Sync.Revision) > 7 {
syncStatusStr += fmt.Sprintf(" (%s)", app.Status.Sync.Revision[0:7])
Expand Down Expand Up @@ -2054,7 +2054,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
if len(list.Items) == 0 {
errMsg := "No matching apps found for filter:"
if selector != "" {
errMsg += fmt.Sprintf(" selector %s", selector)
errMsg += " selector " + selector
}
if len(projects) != 0 {
errMsg += fmt.Sprintf(" projects %v", projects)
Expand Down Expand Up @@ -3149,7 +3149,7 @@ func NewApplicationEditCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
appData, err = yaml.JSONToYAML(appData)
errors.CheckError(err)

cli.InteractiveEdit(fmt.Sprintf("%s-*-edit.yaml", appName), appData, func(input []byte) error {
cli.InteractiveEdit(appName+"-*-edit.yaml", appData, func(input []byte) error {
input, err = yaml.YAMLToJSON(input)
if err != nil {
return fmt.Errorf("error converting YAML to JSON: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/argocd/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie
)
command := &cobra.Command{
Use: "add CONTEXT",
Short: fmt.Sprintf("%s cluster add CONTEXT", cliName),
Short: cliName + " cluster add CONTEXT",
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()

Expand Down Expand Up @@ -541,7 +541,7 @@ argocd cluster list -o server <ARGOCD_SERVER_ADDRESS>
func NewClusterRotateAuthCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
command := &cobra.Command{
Use: "rotate-auth SERVER/NAME",
Short: fmt.Sprintf("%s cluster rotate-auth SERVER/NAME", cliName),
Short: cliName + " cluster rotate-auth SERVER/NAME",
Example: `argocd cluster rotate-auth https://12.34.567.89
argocd cluster rotate-auth cluster-name`,
Run: func(c *cobra.Command, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/headless/headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func MaybeStartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOpti
address = ptr.To("localhost")
}
if port == nil || *port == 0 {
addr := fmt.Sprintf("%s:0", *address)
addr := *address + ":0"
ln, err := net.Listen("tcp", addr)
if err != nil {
return fmt.Errorf("failed to listen on %q: %w", addr, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ func NewProjectEditCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman
projData, err = yaml.JSONToYAML(projData)
errors.CheckError(err)

cli.InteractiveEdit(fmt.Sprintf("%s-*-edit.yaml", projName), projData, func(input []byte) error {
cli.InteractiveEdit(projName+"-*-edit.yaml", projData, func(input []byte) error {
input, err = yaml.YAMLToJSON(input)
if err != nil {
return fmt.Errorf("error converting YAML to JSON: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestSetOptionalRedisPasswordFromKubeConfig(t *testing.T) {
name: "Secret does not exist",
namespace: "default",
expectedPassword: "",
expectedErr: fmt.Sprintf("failed to get secret default/%s", RedisInitialCredentials),
expectedErr: "failed to get secret default/" + RedisInitialCredentials,
secret: nil,
},
{
Expand Down
2 changes: 1 addition & 1 deletion controller/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (h *Hydrator) hydrate(logCtx *log.Entry, apps []*appv1.Application) (string
SyncBranch: syncBranch,
TargetBranch: targetBranch,
DrySha: targetRevision,
CommitMessage: fmt.Sprintf("[Argo CD Bot] hydrate %s", targetRevision),
CommitMessage: "[Argo CD Bot] hydrate " + targetRevision,
Paths: paths,
}

Expand Down
12 changes: 6 additions & 6 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
targetObjs, manifestInfos, revisionUpdated, err = m.GetRepoObjs(app, sources, appLabelKey, revisions, noCache, noRevisionCache, verifySignature, project, rollback, true)
if err != nil {
targetObjs = make([]*unstructured.Unstructured, 0)
msg := fmt.Sprintf("Failed to load target state: %s", err.Error())
msg := "Failed to load target state: " + err.Error()
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: msg, LastTransitionTime: &now})
if firstSeen, ok := m.repoErrorCache.Load(app.Name); ok {
if time.Since(firstSeen.(time.Time)) <= m.repoErrorGracePeriod && !noRevisionCache {
Expand Down Expand Up @@ -564,7 +564,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
targetObjs, err = unmarshalManifests(localManifests)
if err != nil {
targetObjs = make([]*unstructured.Unstructured, 0)
msg := fmt.Sprintf("Failed to load local manifests: %s", err.Error())
msg := "Failed to load local manifests: " + err.Error()
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: msg, LastTransitionTime: &now})
failedToLoadObjs = true
}
Expand All @@ -581,7 +581,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
}
targetObjs, dedupConditions, err := DeduplicateTargetObjects(app.Spec.Destination.Namespace, targetObjs, infoProvider)
if err != nil {
msg := fmt.Sprintf("Failed to deduplicate target state: %s", err.Error())
msg := "Failed to deduplicate target state: " + err.Error()
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: msg, LastTransitionTime: &now})
}
conditions = append(conditions, dedupConditions...)
Expand Down Expand Up @@ -609,7 +609,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
liveObjByKey, err := m.liveStateCache.GetManagedLiveObjs(app, targetObjs)
if err != nil {
liveObjByKey = make(map[kubeutil.ResourceKey]*unstructured.Unstructured)
msg := fmt.Sprintf("Failed to load live state: %s", err.Error())
msg := "Failed to load live state: " + err.Error()
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: msg, LastTransitionTime: &now})
failedToLoadObjs = true
}
Expand Down Expand Up @@ -761,7 +761,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
if err != nil {
diffResults = &diff.DiffResultList{}
failedToLoadObjs = true
msg := fmt.Sprintf("Failed to compare desired state to live state: %s", err.Error())
msg := "Failed to compare desired state to live state: " + err.Error()
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: msg, LastTransitionTime: &now})
}
ts.AddCheckpoint("diff_ms")
Expand Down Expand Up @@ -903,7 +903,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1

healthStatus, err := setApplicationHealth(managedResources, resourceSummaries, resourceOverrides, app, m.persistResourceHealth)
if err != nil {
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: fmt.Sprintf("error setting app health: %s", err.Error()), LastTransitionTime: &now})
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: "error setting app health: " + err.Error(), LastTransitionTime: &now})
}

// Git has already performed the signature verification via its GPG interface, and the result is available
Expand Down
Loading

0 comments on commit f245e8b

Please sign in to comment.