Browse code

fix sprintfQuotedString from go-critic

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Matthieu MOREL authored on 2025/05/27 14:49:47
Showing 5 changed files
... ...
@@ -146,7 +146,6 @@ linters:
146 146
         - regexpSimplify
147 147
         - singleCaseSwitch
148 148
         - sloppyReassign
149
-        - sprintfQuotedString
150 149
         - stringsCompare
151 150
         - stringConcatSimplify
152 151
         - stringXbytes
... ...
@@ -58,7 +58,7 @@ func TestEvents(t *testing.T) {
58 58
 	const expectedURL = "/events"
59 59
 
60 60
 	fltrs := filters.NewArgs(filters.Arg("type", string(events.ContainerEventType)))
61
-	expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType)
61
+	expectedFiltersJSON := fmt.Sprintf(`{"type":{%q:true}}`, events.ContainerEventType)
62 62
 
63 63
 	eventsCases := []struct {
64 64
 		options             events.ListOptions
... ...
@@ -108,7 +108,7 @@ func (o *daemonOptions) installFlags(flags *pflag.FlagSet) {
108 108
 	flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode")
109 109
 	flags.BoolVar(&o.Validate, "validate", false, "Validate daemon configuration and exit")
110 110
 	flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`)
111
-	flags.StringVar(&o.LogFormat, "log-format", string(log.TextFormat), fmt.Sprintf(`Set the logging format ("%s"|"%s")`, log.TextFormat, log.JSONFormat))
111
+	flags.StringVar(&o.LogFormat, "log-format", string(log.TextFormat), fmt.Sprintf(`Set the logging format (%q|%q)`, log.TextFormat, log.JSONFormat))
112 112
 	flags.BoolVar(&o.TLS, FlagTLS, DefaultTLSValue, "Use TLS; implied by --tlsverify")
113 113
 	flags.BoolVar(&o.TLSVerify, FlagTLSVerify, dockerTLSVerify || DefaultTLSValue, "Use TLS and verify the remote")
114 114
 
... ...
@@ -77,7 +77,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *
77 77
 	c.Setenv("PATH", testPath)
78 78
 
79 79
 	cmd := exec.Command("docker-credential-shell-test", "store")
80
-	stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": "%s", "Secret": "%s"}`, privateRegistryURL, s.reg.Username(), s.reg.Password())))
80
+	stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": %q, "Secret": %q}`, privateRegistryURL, s.reg.Username(), s.reg.Password())))
81 81
 	cmd.Stdin = stdin
82 82
 	assert.NilError(c, cmd.Run())
83 83
 
... ...
@@ -95,12 +95,12 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *
95 95
 	b, err := os.ReadFile(configPath)
96 96
 	assert.NilError(c, err)
97 97
 	assert.Assert(c, is.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
98
-	assert.Assert(c, is.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))
98
+	assert.Assert(c, is.Contains(string(b), fmt.Sprintf(`%q: {}`, privateRegistryURL)))
99 99
 
100 100
 	cli.DockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
101 101
 
102 102
 	b, err = os.ReadFile(configPath)
103 103
 	assert.NilError(c, err)
104 104
 	assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
105
-	assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))
105
+	assert.Assert(c, !strings.Contains(string(b), fmt.Sprintf(`%q: {}`, privateRegistryURL)))
106 106
 }
... ...
@@ -1051,7 +1051,7 @@ func (n *Network) delete(force bool, rmLBEndpoint bool) error {
1051 1051
 			name: n.name,
1052 1052
 			id:   n.id,
1053 1053
 			endpoints: sliceutil.Map(eps, func(ep *Endpoint) string {
1054
-				return fmt.Sprintf(`name:"%s" id:"%s"`, ep.name, stringid.TruncateID(ep.id))
1054
+				return fmt.Sprintf(`name:%q id:%q`, ep.name, stringid.TruncateID(ep.id))
1055 1055
 			}),
1056 1056
 		}
1057 1057
 	}