chore(lint): enable sprintfQuotedString rule from go-critic (#23401)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2025-06-15 22:33:20 +02:00
committed by GitHub
parent c6ebc19c1f
commit b6e90ea92c
12 changed files with 25 additions and 26 deletions

View File

@@ -69,7 +69,6 @@ linters:
- rangeValCopy
- regexpSimplify
- sloppyReassign
- sprintfQuotedString
- tooManyResultsChecker
- typeAssertChain
- typeDefFirst

View File

@@ -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

View File

@@ -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().

View File

@@ -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().

View File

@@ -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().

View File

@@ -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)

View File

@@ -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().

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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"}`
}

View File

@@ -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
}