From b6e90ea92cf6808756762425703bd8e55bcbf499 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sun, 15 Jun 2025 22:33:20 +0200 Subject: [PATCH] chore(lint): enable sprintfQuotedString rule from go-critic (#23401) Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - server/badge/badge.go | 6 +++--- test/e2e/app_management_ns_test.go | 2 +- test/e2e/app_management_test.go | 4 ++-- test/e2e/hook_test.go | 4 ++-- test/e2e/project_management_test.go | 2 +- test/e2e/selective_sync_test.go | 8 ++++---- test/e2e/sync_with_impersonate_test.go | 2 +- util/grpc/logging_test.go | 2 +- util/helm/client_test.go | 4 ++-- util/helm/creds_test.go | 14 +++++++------- util/webhook/webhook_test.go | 2 +- 12 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index e1c00241cf..4489803c07 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -69,7 +69,6 @@ linters: - rangeValCopy - regexpSimplify - sloppyReassign - - sprintfQuotedString - tooManyResultsChecker - typeAssertChain - typeDefFirst diff --git a/server/badge/badge.go b/server/badge/badge.go index 3f33e7a6ff..5b0e04c8a5 100644 --- a/server/badge/badge.go +++ b/server/badge/badge.go @@ -192,15 +192,15 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } badge := assets.BadgeSVG - badge = leftRectColorPattern.ReplaceAllString(badge, fmt.Sprintf(`id="leftRect" fill="%s" $2`, leftColorString)) - badge = rightRectColorPattern.ReplaceAllString(badge, fmt.Sprintf(`id="rightRect" fill="%s" $2`, rightColorString)) + badge = leftRectColorPattern.ReplaceAllString(badge, fmt.Sprintf(`id="leftRect" fill=%q $2`, leftColorString)) + badge = rightRectColorPattern.ReplaceAllString(badge, fmt.Sprintf(`id="rightRect" fill=%q $2`, rightColorString)) badge = replaceFirstGroupSubMatch(leftTextPattern, badge, leftText) badge = replaceFirstGroupSubMatch(rightTextPattern, badge, rightText) if !notFound && revisionEnabled && revision != "" { // Enable display of revision components badge = displayNonePattern.ReplaceAllString(badge, `display="inline"`) - badge = revisionRectColorPattern.ReplaceAllString(badge, fmt.Sprintf(`id="revisionRect" fill="%s" $2`, rightColorString)) + badge = revisionRectColorPattern.ReplaceAllString(badge, fmt.Sprintf(`id="revisionRect" fill=%q $2`, rightColorString)) adjustWidth = true displayedRevision = revision diff --git a/test/e2e/app_management_ns_test.go b/test/e2e/app_management_ns_test.go index 267af7bd46..3cf9b93985 100644 --- a/test/e2e/app_management_ns_test.go +++ b/test/e2e/app_management_ns_test.go @@ -1337,7 +1337,7 @@ func TestNamespacedSelfManagedApps(t *testing.T) { SetTrackingMethod("annotation"). SetAppNamespace(fixture.AppNamespace()). When(). - PatchFile("resources.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/spec/source/repoURL", "value": "%s"}]`, fixture.RepoURL(fixture.RepoURLTypeFile))). + PatchFile("resources.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/spec/source/repoURL", "value": %q}]`, fixture.RepoURL(fixture.RepoURLTypeFile))). CreateApp(). Sync(). Then(). diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index 766084f54d..434918ec35 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -1807,7 +1807,7 @@ func TestSourceNamespaceCanBeMigratedToManagedNamespaceWithoutBeingPrunedOrOutOf Prune(true). Path("guestbook-with-plain-namespace-manifest"). When(). - PatchFile("guestbook-ui-namespace.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/name", "value": "%s"}]`, fixture.DeploymentNamespace())). + PatchFile("guestbook-ui-namespace.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/name", "value": %q}]`, fixture.DeploymentNamespace())). CreateApp(). Sync(). Then(). @@ -1840,7 +1840,7 @@ func TestSelfManagedApps(t *testing.T) { Given(t). Path("self-managed-app"). When(). - PatchFile("resources.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/spec/source/repoURL", "value": "%s"}]`, fixture.RepoURL(fixture.RepoURLTypeFile))). + PatchFile("resources.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/spec/source/repoURL", "value": %q}]`, fixture.RepoURL(fixture.RepoURLTypeFile))). CreateApp(). Sync(). Then(). diff --git a/test/e2e/hook_test.go b/test/e2e/hook_test.go index 214f727bb4..a350bfaadf 100644 --- a/test/e2e/hook_test.go +++ b/test/e2e/hook_test.go @@ -40,7 +40,7 @@ func testHookSuccessful(t *testing.T, hookType HookType) { Given(t). Path("hook"). When(). - PatchFile("hook.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/annotations", "value": {"argocd.argoproj.io/hook": "%s"}}]`, hookType)). + PatchFile("hook.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/annotations", "value": {"argocd.argoproj.io/hook": %q}}]`, hookType)). CreateApp(). Sync(). Then(). @@ -469,7 +469,7 @@ func testHookFinalizer(t *testing.T, hookType HookType) { }). Path("hook-resource-deleted-externally"). When(). - PatchFile("hook.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/annotations", "value": {"argocd.argoproj.io/hook": "%s"}}]`, hookType)). + PatchFile("hook.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/annotations", "value": {"argocd.argoproj.io/hook": %q}}]`, hookType)). CreateApp(). Sync(). Then(). diff --git a/test/e2e/project_management_test.go b/test/e2e/project_management_test.go index 45d673970a..e5b206c56c 100644 --- a/test/e2e/project_management_test.go +++ b/test/e2e/project_management_test.go @@ -344,7 +344,7 @@ func TestUseJWTToken(t *testing.T) { // Create second role with kubectl, to test that it will not affect 1st role _, err = fixture.Run("", "kubectl", "patch", "appproject", projectName, "--type", "merge", "-n", fixture.TestNamespace(), - "-p", fmt.Sprintf(`{"spec":{"roles":[{"name":"%s"},{"name":"%s"}]}}`, roleName, roleName2)) + "-p", fmt.Sprintf(`{"spec":{"roles":[{"name":%q},{"name":%q}]}}`, roleName, roleName2)) require.NoError(t, err) _, err = fixture.RunCli("proj", "role", "create-token", projectName, roleName2) diff --git a/test/e2e/selective_sync_test.go b/test/e2e/selective_sync_test.go index 4107c742af..50ad6484ff 100644 --- a/test/e2e/selective_sync_test.go +++ b/test/e2e/selective_sync_test.go @@ -65,8 +65,8 @@ func TestSelectiveSyncWithoutNamespace(t *testing.T) { }). SelectedResource("apps:Deployment:guestbook-ui"). When(). - PatchFile("guestbook-ui-deployment-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). - PatchFile("guestbook-ui-svc-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). + PatchFile("guestbook-ui-deployment-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": %q}]`, selectedResourceNamespace)). + PatchFile("guestbook-ui-svc-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": %q}]`, selectedResourceNamespace)). CreateApp(). Sync(). Then(). @@ -95,8 +95,8 @@ func TestSelectiveSyncWithNamespace(t *testing.T) { }). SelectedResource(fmt.Sprintf("apps:Deployment:%s/guestbook-ui", selectedResourceNamespace)). When(). - PatchFile("guestbook-ui-deployment-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). - PatchFile("guestbook-ui-svc-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). + PatchFile("guestbook-ui-deployment-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": %q}]`, selectedResourceNamespace)). + PatchFile("guestbook-ui-svc-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": %q}]`, selectedResourceNamespace)). CreateApp(). Sync(). Then(). diff --git a/test/e2e/sync_with_impersonate_test.go b/test/e2e/sync_with_impersonate_test.go index d2e6ef9348..65919a69dd 100644 --- a/test/e2e/sync_with_impersonate_test.go +++ b/test/e2e/sync_with_impersonate_test.go @@ -197,7 +197,7 @@ func TestSyncWithValidSAButDisallowedDestination(t *testing.T) { When(). And(func() { // Patch destination to disallow target destination namespace - patch := []byte(fmt.Sprintf(`{"spec": {"destinations": [{"namespace": "%s"}]}}`, "!"+fixture.DeploymentNamespace())) + patch := []byte(fmt.Sprintf(`{"spec": {"destinations": [{"namespace": %q}]}}`, "!"+fixture.DeploymentNamespace())) _, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Patch(t.Context(), projectName, types.MergePatchType, patch, metav1.PatchOptions{}) require.NoError(t, err) diff --git a/util/grpc/logging_test.go b/util/grpc/logging_test.go index e3e549701b..0603d531ef 100644 --- a/util/grpc/logging_test.go +++ b/util/grpc/logging_test.go @@ -38,7 +38,7 @@ func Test_JSONLogging(t *testing.T) { require.NoError(t, err) out := buf.String() - assert.Contains(t, out, fmt.Sprintf(`"grpc.request.content":{"name":"%s"`, req.Name)) + assert.Contains(t, out, fmt.Sprintf(`"grpc.request.content":{"name":%q`, req.Name)) } func Test_logRequest(t *testing.T) { diff --git a/util/helm/client_test.go b/util/helm/client_test.go index acfd230cd6..21765b9270 100644 --- a/util/helm/client_test.go +++ b/util/helm/client_test.go @@ -316,7 +316,7 @@ func TestGetTagsFromURLPrivateRepoWithAzureWorkloadIdentityAuthentication(t *tes switch r.URL.Path { case "/v2/": - w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm="%s",service="%s"`, mockedServerURL(), mockedServerURL()[8:])) + w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm=%q,service=%q`, mockedServerURL(), mockedServerURL()[8:])) w.WriteHeader(http.StatusUnauthorized) case "/oauth2/exchange": @@ -437,7 +437,7 @@ func TestGetTagsFromURLEnvironmentAuthentication(t *testing.T) { configPath := filepath.Join(tempDir, "config.json") t.Setenv("DOCKER_CONFIG", tempDir) - config := fmt.Sprintf(`{"auths":{"%s":{"auth":"%s"}}}`, server.URL, bearerToken) + config := fmt.Sprintf(`{"auths":{%q:{"auth":%q}}}`, server.URL, bearerToken) require.NoError(t, os.WriteFile(configPath, []byte(config), 0o666)) testCases := []struct { diff --git a/util/helm/creds_test.go b/util/helm/creds_test.go index 999f886ed0..532ebbc066 100644 --- a/util/helm/creds_test.go +++ b/util/helm/creds_test.go @@ -67,7 +67,7 @@ func TestGetPasswordShouldGenerateTokenIfNotPresentInCache(t *testing.T) { mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/v2/": - w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm="%s",service="%s"`, mockedServerURL(), mockedServerURL()[8:])) + w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm=%q,service=%q`, mockedServerURL(), mockedServerURL()[8:])) w.WriteHeader(http.StatusUnauthorized) case "/oauth2/exchange": @@ -281,16 +281,16 @@ func TestGetAccessToken_FetchNewTokenIfExistingIsExpired(t *testing.T) { switch r.URL.Path { case "/v2/": assert.Equal(t, "/v2/", r.URL.Path) - w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm="%s",service="%s"`, mockedServerURL(), mockedServerURL()[8:])) + w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm=%q,service=%q`, mockedServerURL(), mockedServerURL()[8:])) w.WriteHeader(http.StatusUnauthorized) case "/oauth2/exchange": assert.Equal(t, "/oauth2/exchange", r.URL.Path) var response string switch callCount { case 0: - response = fmt.Sprintf(`{"refresh_token": "%s"}`, accessToken1) + response = fmt.Sprintf(`{"refresh_token": %q}`, accessToken1) case 1: - response = fmt.Sprintf(`{"refresh_token": "%s"}`, accessToken2) + response = fmt.Sprintf(`{"refresh_token": %q}`, accessToken2) default: response = `{"refresh_token": "defaultToken"}` } @@ -335,16 +335,16 @@ func TestGetAccessToken_ReuseTokenIfExistingIsNotExpired(t *testing.T) { switch r.URL.Path { case "/v2/": assert.Equal(t, "/v2/", r.URL.Path) - w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm="%s",service="%s"`, mockedServerURL(), mockedServerURL()[8:])) + w.Header().Set("Www-Authenticate", fmt.Sprintf(`Bearer realm=%q,service=%q`, mockedServerURL(), mockedServerURL()[8:])) w.WriteHeader(http.StatusUnauthorized) case "/oauth2/exchange": assert.Equal(t, "/oauth2/exchange", r.URL.Path) var response string switch callCount { case 0: - response = fmt.Sprintf(`{"refresh_token": "%s"}`, accessToken1) + response = fmt.Sprintf(`{"refresh_token": %q}`, accessToken1) case 1: - response = fmt.Sprintf(`{"refresh_token": "%s"}`, accessToken2) + response = fmt.Sprintf(`{"refresh_token": %q}`, accessToken2) default: response = `{"refresh_token": "defaultToken"}` } diff --git a/util/webhook/webhook_test.go b/util/webhook/webhook_test.go index 20a37efec6..c341f9323f 100644 --- a/util/webhook/webhook_test.go +++ b/util/webhook/webhook_test.go @@ -618,7 +618,7 @@ func Test_affectedRevisionInfo_appRevisionHasChanged(t *testing.T) { // The payload's "push.changes[0].new.name" member seems to only have the branch name (based on the example payload). // https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#EventPayloads-Push var pl bitbucket.RepoPushPayload - _ = json.Unmarshal([]byte(fmt.Sprintf(`{"push":{"changes":[{"new":{"name":"%s"}}]}}`, branchName)), &pl) + _ = json.Unmarshal([]byte(fmt.Sprintf(`{"push":{"changes":[{"new":{"name":%q}}]}}`, branchName)), &pl) return pl }