From a62de57aa1320ddfa6a894225121bbf65c40de19 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Tue, 27 May 2025 07:49:47 +0200 Subject: [PATCH] fix sprintfQuotedString from go-critic Signed-off-by: Matthieu MOREL --- .golangci.yml | 1 - client/events_test.go | 2 +- cmd/dockerd/options.go | 2 +- integration-cli/docker_cli_logout_test.go | 6 +++--- libnetwork/network.go | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 002fe8c65a..82680200fe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -146,7 +146,6 @@ linters: - regexpSimplify - singleCaseSwitch - sloppyReassign - - sprintfQuotedString - stringsCompare - stringConcatSimplify - stringXbytes diff --git a/client/events_test.go b/client/events_test.go index 5823772045..b699ea28c8 100644 --- a/client/events_test.go +++ b/client/events_test.go @@ -58,7 +58,7 @@ func TestEvents(t *testing.T) { const expectedURL = "/events" fltrs := filters.NewArgs(filters.Arg("type", string(events.ContainerEventType))) - expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType) + expectedFiltersJSON := fmt.Sprintf(`{"type":{%q:true}}`, events.ContainerEventType) eventsCases := []struct { options events.ListOptions diff --git a/cmd/dockerd/options.go b/cmd/dockerd/options.go index aba6613d5c..de745c584f 100644 --- a/cmd/dockerd/options.go +++ b/cmd/dockerd/options.go @@ -108,7 +108,7 @@ func (o *daemonOptions) installFlags(flags *pflag.FlagSet) { flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode") flags.BoolVar(&o.Validate, "validate", false, "Validate daemon configuration and exit") flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) - flags.StringVar(&o.LogFormat, "log-format", string(log.TextFormat), fmt.Sprintf(`Set the logging format ("%s"|"%s")`, log.TextFormat, log.JSONFormat)) + flags.StringVar(&o.LogFormat, "log-format", string(log.TextFormat), fmt.Sprintf(`Set the logging format (%q|%q)`, log.TextFormat, log.JSONFormat)) flags.BoolVar(&o.TLS, FlagTLS, DefaultTLSValue, "Use TLS; implied by --tlsverify") flags.BoolVar(&o.TLSVerify, FlagTLSVerify, dockerTLSVerify || DefaultTLSValue, "Use TLS and verify the remote") diff --git a/integration-cli/docker_cli_logout_test.go b/integration-cli/docker_cli_logout_test.go index 4c32ff644e..a5880a9fbd 100644 --- a/integration-cli/docker_cli_logout_test.go +++ b/integration-cli/docker_cli_logout_test.go @@ -77,7 +77,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c * c.Setenv("PATH", testPath) cmd := exec.Command("docker-credential-shell-test", "store") - stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": "%s", "Secret": "%s"}`, privateRegistryURL, s.reg.Username(), s.reg.Password()))) + stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": %q, "Secret": %q}`, privateRegistryURL, s.reg.Username(), s.reg.Password()))) cmd.Stdin = stdin assert.NilError(c, cmd.Run()) @@ -95,12 +95,12 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c * b, err := os.ReadFile(configPath) assert.NilError(c, err) assert.Assert(c, is.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL))) - assert.Assert(c, is.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL))) + assert.Assert(c, is.Contains(string(b), fmt.Sprintf(`%q: {}`, privateRegistryURL))) cli.DockerCmd(c, "--config", tmp, "logout", privateRegistryURL) b, err = os.ReadFile(configPath) assert.NilError(c, err) assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL))) - assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL))) + assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`%q: {}`, privateRegistryURL))) } diff --git a/libnetwork/network.go b/libnetwork/network.go index 9d3d25cc00..96b6cf4949 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -1051,7 +1051,7 @@ func (n *Network) delete(force bool, rmLBEndpoint bool) error { name: n.name, id: n.id, endpoints: sliceutil.Map(eps, func(ep *Endpoint) string { - return fmt.Sprintf(`name:"%s" id:"%s"`, ep.name, stringid.TruncateID(ep.id)) + return fmt.Sprintf(`name:%q id:%q`, ep.name, stringid.TruncateID(ep.id)) }), } }