Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8ea897

Browse files
committed
chore: remove unnecessary redelarations in for loops
1 parent 56ff0fb commit d8ea897

File tree

214 files changed

+296
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+296
-378
lines changed

agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func (a *agent) reportMetadata(ctx context.Context, aAPI proto.DRPCAgentClient26
547547
// channel to synchronize the results and avoid both messy
548548
// mutex logic and overloading the API.
549549
for _, md := range manifest.Metadata {
550-
md := md
550+
551551
// We send the result to the channel in the goroutine to avoid
552552
// sending the same result multiple times. So, we don't care about
553553
// the return values.

agent/agent_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestAgent_Stats_SSH(t *testing.T) {
130130
t.Parallel()
131131

132132
for _, port := range sshPorts {
133-
port := port
133+
134134
t.Run(fmt.Sprintf("(:%d)", port), func(t *testing.T) {
135135
t.Parallel()
136136

@@ -342,7 +342,7 @@ func TestAgent_SessionExec(t *testing.T) {
342342
t.Parallel()
343343

344344
for _, port := range sshPorts {
345-
port := port
345+
346346
t.Run(fmt.Sprintf("(:%d)", port), func(t *testing.T) {
347347
t.Parallel()
348348

@@ -468,7 +468,7 @@ func TestAgent_SessionTTYShell(t *testing.T) {
468468
}
469469

470470
for _, port := range sshPorts {
471-
port := port
471+
472472
t.Run(fmt.Sprintf("(%d)", port), func(t *testing.T) {
473473
t.Parallel()
474474

@@ -611,7 +611,7 @@ func TestAgent_Session_TTY_MOTD(t *testing.T) {
611611
}
612612

613613
for _, test := range tests {
614-
test := test
614+
615615
t.Run(test.name, func(t *testing.T) {
616616
t.Parallel()
617617
session := setupSSHSession(t, test.manifest, test.banner, func(fs afero.Fs) {
@@ -688,7 +688,6 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {
688688

689689
//nolint:paralleltest // These tests need to swap the banner func.
690690
for _, port := range sshPorts {
691-
port := port
692691

693692
sshClient, err := conn.SSHClientOnPort(ctx, port)
694693
require.NoError(t, err)
@@ -697,7 +696,7 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {
697696
})
698697

699698
for i, test := range tests {
700-
test := test
699+
701700
t.Run(fmt.Sprintf("(:%d)/%d", port, i), func(t *testing.T) {
702701
// Set new banner func and wait for the agent to call it to update the
703702
// banner.
@@ -1210,7 +1209,7 @@ func TestAgent_CoderEnvVars(t *testing.T) {
12101209
t.Parallel()
12111210

12121211
for _, key := range []string{"CODER", "CODER_WORKSPACE_NAME", "CODER_WORKSPACE_AGENT_NAME"} {
1213-
key := key
1212+
12141213
t.Run(key, func(t *testing.T) {
12151214
t.Parallel()
12161215

@@ -1233,7 +1232,7 @@ func TestAgent_SSHConnectionEnvVars(t *testing.T) {
12331232
// For some reason this test produces a TTY locally and a non-TTY in CI
12341233
// so we don't test for the absence of SSH_TTY.
12351234
for _, key := range []string{"SSH_CONNECTION", "SSH_CLIENT"} {
1236-
key := key
1235+
12371236
t.Run(key, func(t *testing.T) {
12381237
t.Parallel()
12391238

@@ -1276,7 +1275,7 @@ func TestAgent_SSHConnectionLoginVars(t *testing.T) {
12761275
},
12771276
}
12781277
for _, tt := range tests {
1279-
tt := tt
1278+
12801279
t.Run(tt.key, func(t *testing.T) {
12811280
t.Parallel()
12821281

@@ -1796,7 +1795,7 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
17961795
t.Setenv("LANG", "C")
17971796

17981797
for _, backendType := range backends {
1799-
backendType := backendType
1798+
18001799
t.Run(backendType, func(t *testing.T) {
18011800
if backendType == "Screen" {
18021801
if runtime.GOOS != "linux" {
@@ -2496,7 +2495,7 @@ func TestAgent_Dial(t *testing.T) {
24962495
}
24972496

24982497
for _, c := range cases {
2499-
c := c
2498+
25002499
t.Run(c.name, func(t *testing.T) {
25012500
t.Parallel()
25022501

agent/agentcontainers/containers_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestWrapDockerExec(t *testing.T) {
4141
},
4242
}
4343
for _, tt := range tests {
44-
tt := tt // appease the linter even though this isn't needed anymore
44+
// appease the linter even though this isn't needed anymore
4545
t.Run(tt.name, func(t *testing.T) {
4646
t.Parallel()
4747
actualCmd, actualArgs := wrapDockerExec("my-container", tt.containerUser, tt.cmdArgs[0], tt.cmdArgs[1:]...)
@@ -151,7 +151,7 @@ func TestConvertDockerVolume(t *testing.T) {
151151
expectError: "invalid volume",
152152
},
153153
} {
154-
tc := tc
154+
155155
t.Run(tc.name, func(t *testing.T) {
156156
t.Parallel()
157157
})

agent/agentscripts/agentscripts.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript, scriptCompleted S
177177
if script.Cron == "" {
178178
continue
179179
}
180-
script := script
180+
181181
_, err := r.cron.AddFunc(script.Cron, func() {
182182
err := r.trackRun(r.cronCtx, script.WorkspaceAgentScript, ExecuteCronScripts)
183183
if err != nil {
@@ -254,7 +254,6 @@ func (r *Runner) Execute(ctx context.Context, option ExecuteOption) error {
254254
continue
255255
}
256256

257-
script := script
258257
eg.Go(func() error {
259258
err := r.trackRun(ctx, script.WorkspaceAgentScript, option)
260259
if err != nil {

agent/agentssh/x11_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func Test_addXauthEntry(t *testing.T) {
228228
require.NoError(t, err)
229229

230230
for _, tt := range tests {
231-
tt := tt
231+
232232
t.Run(tt.name, func(t *testing.T) {
233233
t.Parallel()
234234

agent/proto/compare_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestLabelsEqual(t *testing.T) {
6767
eq: false,
6868
},
6969
} {
70-
tc := tc
70+
7171
t.Run(tc.name, func(t *testing.T) {
7272
t.Parallel()
7373
require.Equal(t, tc.eq, proto.LabelsEqual(tc.a, tc.b))

agent/proto/resourcesmonitor/queue_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func TestResourceMonitorQueue(t *testing.T) {
6565
}
6666

6767
for _, tt := range tests {
68-
tt := tt
6968

7069
t.Run(tt.name, func(t *testing.T) {
7170
t.Parallel()

agent/proto/resourcesmonitor/resources_monitor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestPushResourcesMonitoringWithConfig(t *testing.T) {
195195
}
196196

197197
for _, tt := range tests {
198-
tt := tt
198+
199199
t.Run(tt.name, func(t *testing.T) {
200200
t.Parallel()
201201

apiversion/apiversion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestAPIVersionValidate(t *testing.T) {
7272
expectedError: "no longer supported",
7373
},
7474
} {
75-
tc := tc
75+
7676
t.Run(tc.name, func(t *testing.T) {
7777
t.Parallel()
7878

buildinfo/buildinfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestBuildInfo(t *testing.T) {
9393
}
9494

9595
for _, c := range cases {
96-
c := c
96+
9797
t.Run(c.name, func(t *testing.T) {
9898
t.Parallel()
9999
require.Equal(t, c.expectMatch, buildinfo.VersionsMatch(c.v1, c.v2),

cli/agent_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Test_extractPort(t *testing.T) {
5454
},
5555
}
5656
for _, tt := range tests {
57-
tt := tt
57+
5858
t.Run(tt.name, func(t *testing.T) {
5959
t.Parallel()
6060
got, err := extractPort(tt.urlString)

cli/autoupdate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestAutoUpdate(t *testing.T) {
6262
}
6363

6464
for _, c := range cases {
65-
c := c
65+
6666
t.Run(c.Name, func(t *testing.T) {
6767
t.Parallel()
6868
client := coderdtest.New(t, nil)

cli/clitest/golden.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ExtractCommandPathsLoop:
7171
}
7272

7373
for _, tt := range cases {
74-
tt := tt
74+
7575
t.Run(tt.Name, func(t *testing.T) {
7676
t.Parallel()
7777
ctx := testutil.Context(t, testutil.WaitLong)

cli/cliui/agent_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func TestAgent(t *testing.T) {
369369
wantErr: true,
370370
},
371371
} {
372-
tc := tc
372+
373373
t.Run(tc.name, func(t *testing.T) {
374374
t.Parallel()
375375

@@ -648,7 +648,7 @@ func TestPeerDiagnostics(t *testing.T) {
648648
},
649649
}
650650
for _, tc := range testCases {
651-
tc := tc
651+
652652
t.Run(tc.name, func(t *testing.T) {
653653
t.Parallel()
654654
r, w := io.Pipe()
@@ -852,7 +852,7 @@ func TestConnDiagnostics(t *testing.T) {
852852
},
853853
}
854854
for _, tc := range testCases {
855-
tc := tc
855+
856856
t.Run(tc.name, func(t *testing.T) {
857857
t.Parallel()
858858
r, w := io.Pipe()

cli/cliui/provisionerjob_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func TestProvisionerJob(t *testing.T) {
124124
}
125125

126126
for _, tc := range tests {
127-
tc := tc
128127

129128
t.Run(tc.name, func(t *testing.T) {
130129
t.Parallel()

cli/cliui/resources_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestRenderAgentVersion(t *testing.T) {
4040
},
4141
}
4242
for _, testCase := range testCases {
43-
testCase := testCase
43+
4444
t.Run(testCase.name, func(t *testing.T) {
4545
t.Parallel()
4646
actual := renderAgentVersion(testCase.agentVersion, testCase.serverVersion)

cli/cliui/table_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ foo <nil> 10 [a, b, c] foo1 11 foo2 12 fo
169169
// Test with pointer values.
170170
inPtr := make([]*tableTest1, len(in))
171171
for i, v := range in {
172-
v := v
172+
173173
inPtr[i] = &v
174174
}
175175
out, err = cliui.DisplayTable(inPtr, "", nil)

cli/cliutil/levenshtein/levenshtein_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Test_Levenshtein_Matches(t *testing.T) {
9595
Expected: []string{"kubernetes"},
9696
},
9797
} {
98-
tt := tt
98+
9999
t.Run(tt.Name, func(t *testing.T) {
100100
t.Parallel()
101101
actual := levenshtein.Matches(tt.Needle, tt.MaxDistance, tt.Haystack...)
@@ -179,7 +179,7 @@ func Test_Levenshtein_Distance(t *testing.T) {
179179
Error: levenshtein.ErrMaxDist.Error(),
180180
},
181181
} {
182-
tt := tt
182+
183183
t.Run(tt.Name, func(t *testing.T) {
184184
t.Parallel()
185185
actual, err := levenshtein.Distance(tt.A, tt.B, tt.MaxDist)

cli/cliutil/provisionerwarn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestWarnMatchedProvisioners(t *testing.T) {
5959
},
6060
},
6161
} {
62-
tt := tt
62+
6363
t.Run(tt.name, func(t *testing.T) {
6464
t.Parallel()
6565
var w strings.Builder

cli/configssh_internal_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func Test_sshConfigSplitOnCoderSection(t *testing.T) {
118118
}
119119

120120
for _, tc := range testCases {
121-
tc := tc
121+
122122
t.Run(tc.Name, func(t *testing.T) {
123123
t.Parallel()
124124

@@ -157,7 +157,7 @@ func Test_sshConfigProxyCommandEscape(t *testing.T) {
157157
}
158158
// nolint:paralleltest // Fixes a flake
159159
for _, tt := range tests {
160-
tt := tt
160+
161161
t.Run(tt.name, func(t *testing.T) {
162162
if runtime.GOOS == "windows" {
163163
t.Skip("Windows doesn't typically execute via /bin/sh or cmd.exe, so this test is not applicable.")
@@ -207,7 +207,7 @@ func Test_sshConfigMatchExecEscape(t *testing.T) {
207207
}
208208
// nolint:paralleltest // Fixes a flake
209209
for _, tt := range tests {
210-
tt := tt
210+
211211
t.Run(tt.name, func(t *testing.T) {
212212
cmd := "/bin/sh"
213213
arg := "-c"
@@ -290,7 +290,7 @@ func Test_sshConfigExecEscapeSeparatorForce(t *testing.T) {
290290
},
291291
}
292292
for _, tt := range tests {
293-
tt := tt
293+
294294
t.Run(tt.name, func(t *testing.T) {
295295
t.Parallel()
296296
found, err := sshConfigProxyCommandEscape(tt.path, tt.forceUnix)
@@ -366,7 +366,7 @@ func Test_sshConfigOptions_addOption(t *testing.T) {
366366
}
367367

368368
for _, tt := range testCases {
369-
tt := tt
369+
370370
t.Run(tt.Name, func(t *testing.T) {
371371
t.Parallel()
372372

cli/configssh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
688688
},
689689
}
690690
for _, tt := range tests {
691-
tt := tt
691+
692692
t.Run(tt.name, func(t *testing.T) {
693693
t.Parallel()
694694

cli/exp_errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ExtractCommandPathsLoop:
4949
}
5050

5151
for _, tt := range cases {
52-
tt := tt
52+
5353
t.Run(tt.Name, func(t *testing.T) {
5454
t.Parallel()
5555

cli/gitauth/askpass_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestParse(t *testing.T) {
6060
wantHost: "http://wow.io",
6161
},
6262
} {
63-
tc := tc
63+
6464
t.Run(tc.in, func(t *testing.T) {
6565
t.Parallel()
6666
user, host, err := gitauth.ParseAskpass(tc.in)

cli/notifications_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestNotifications(t *testing.T) {
4848
}
4949

5050
for _, tt := range tests {
51-
tt := tt
51+
5252
t.Run(tt.name, func(t *testing.T) {
5353
t.Parallel()
5454

0 commit comments

Comments
 (0)