Skip to content

Commit f3089d5

Browse files
committed
golangci-lint: Add copyloopvar + autofix + manual fixes
1 parent a81e3f0 commit f3089d5

File tree

125 files changed

+1
-387
lines changed

Some content is hidden

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

125 files changed

+1
-387
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ linters:
1010
- bodyclose
1111
- canonicalheader
1212
- contextcheck
13+
- copyloopvar
1314
- cyclop
1415
- dogsled
1516
- dupl

api/v1/group_routes_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func TestGetGroups(t *testing.T) {
155155
})
156156
})
157157
for _, gp := range []*lib.Group{g0, g1, g2} {
158-
gp := gp
159158
t.Run(gp.Name, func(t *testing.T) {
160159
t.Parallel()
161160
rw := httptest.NewRecorder()

api/v1/metric_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func TestNullMetricTypeJSON(t *testing.T) {
2525
t.Parallel()
2626

2727
for mt, val := range values {
28-
mt, val := mt, val
2928
t.Run(val, func(t *testing.T) {
3029
t.Parallel()
3130

@@ -39,7 +38,6 @@ func TestNullMetricTypeJSON(t *testing.T) {
3938
t.Parallel()
4039

4140
for mt, val := range values {
42-
mt, val := mt, val
4341
t.Run(val, func(t *testing.T) {
4442
t.Parallel()
4543

@@ -63,7 +61,6 @@ func TestNullValueTypeJSON(t *testing.T) {
6361
t.Parallel()
6462

6563
for mt, val := range values {
66-
mt, val := mt, val
6764
t.Run(val, func(t *testing.T) {
6865
t.Parallel()
6966

@@ -77,7 +74,6 @@ func TestNullValueTypeJSON(t *testing.T) {
7774
t.Parallel()
7875

7976
for mt, val := range values {
80-
mt, val := mt, val
8177
t.Run(val, func(t *testing.T) {
8278
t.Parallel()
8379

api/v1/setup_teardown_routes_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ func TestSetupData(t *testing.T) {
206206
}
207207

208208
for id := range testCases {
209-
id := id
210209
t.Run(fmt.Sprintf("testcase_%d", id), func(t *testing.T) {
211210
t.Parallel()
212211
runTestCase(t, id)

api/v1/status_routes_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ func TestPatchStatus(t *testing.T) {
105105
}
106106

107107
for name, testCase := range testData {
108-
name, testCase := name, testCase
109108
t.Run(name, func(t *testing.T) {
110109
t.Parallel()
111110

cloudapi/logs_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ func TestRetry(t *testing.T) {
150150
}
151151

152152
for _, tt := range tests {
153-
tt := tt
154153
t.Run(tt.name, func(t *testing.T) {
155154
t.Parallel()
156155
var sleepRequests []time.Duration

internal/api/server_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ func testHTTPHandler(rw http.ResponseWriter, _ *http.Request) {
2323
func TestLogger(t *testing.T) {
2424
t.Parallel()
2525
for _, method := range []string{"GET", "POST", "PUT", "PATCH"} {
26-
method := method
2726
t.Run("method="+method, func(t *testing.T) {
2827
t.Parallel()
2928
for _, path := range []string{"/", "/test", "/test/path"} {
30-
path := path
3129
t.Run("path="+path, func(t *testing.T) {
3230
t.Parallel()
3331
rw := httptest.NewRecorder()

internal/cmd/archive_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func TestArchiveThresholds(t *testing.T) {
6969
}
7070

7171
for _, testCase := range testCases {
72-
testCase := testCase
7372
t.Run(testCase.name, func(t *testing.T) {
7473
t.Parallel()
7574

internal/cmd/config_consolidation_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,11 @@ func TestConfigConsolidation(t *testing.T) {
580580
t.Parallel()
581581

582582
for tcNum, testCase := range getConfigConsolidationTestCases() {
583-
tcNum, testCase := tcNum, testCase
584583
subCommands := testCase.options.cmds
585584
if subCommands == nil { // handle the most common case
586585
subCommands = []string{"run", "archive", "cloud"}
587586
}
588587
for fsNum, subCmd := range subCommands {
589-
fsNum, subCmd := fsNum, subCmd
590588
t.Run(
591589
fmt.Sprintf("TestCase#%d_FlagSet#%d", tcNum, fsNum),
592590
func(t *testing.T) {

internal/cmd/config_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ func TestConfigCmd(t *testing.T) {
6060
}
6161

6262
for _, data := range testdata {
63-
data := data
6463
t.Run(data.Name, func(t *testing.T) {
6564
t.Parallel()
6665
for _, test := range data.Tests {
67-
test := test
6866
t.Run(`"`+test.Name+`"`, func(t *testing.T) {
6967
t.Parallel()
7068
fs := configFlagSet()
@@ -104,11 +102,9 @@ func TestConfigEnv(t *testing.T) {
104102
},
105103
}
106104
for field, data := range testdata {
107-
field, data := field, data
108105
t.Run(field.Name, func(t *testing.T) {
109106
t.Parallel()
110107
for value, fn := range data {
111-
value, fn := value, fn
112108
t.Run(`"`+value+`"`, func(t *testing.T) {
113109
t.Parallel()
114110
var config Config
@@ -193,7 +189,6 @@ func TestDeriveAndValidateConfig(t *testing.T) {
193189
}
194190

195191
for _, tc := range testCases {
196-
tc := tc
197192
t.Run(tc.name, func(t *testing.T) {
198193
t.Parallel()
199194
_, err := deriveAndValidateConfig(tc.conf,
@@ -499,7 +494,6 @@ func TestLoadConfig(t *testing.T) {
499494
},
500495
}
501496
for _, tc := range testcases {
502-
tc := tc
503497
t.Run(tc.name, func(t *testing.T) {
504498
t.Parallel()
505499
l, hook := testutils.NewLoggerWithHook(t)

internal/cmd/new_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func TestNewScriptCmd(t *testing.T) {
3939
}
4040

4141
for _, testCase := range testCases {
42-
testCase := testCase
4342
t.Run(testCase.name, func(t *testing.T) {
4443
t.Parallel()
4544

internal/cmd/options_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func TestParseTagKeyValue(t *testing.T) {
5353
}
5454

5555
for _, data := range testData {
56-
data := data
5756
t.Run(data.input, func(t *testing.T) {
5857
t.Parallel()
5958
name, value, err := parseTagNameValue(data.input)

internal/cmd/root_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ func TestRootCommandHelpDisplayCommands(t *testing.T) {
7373
}
7474

7575
for _, tc := range testCases {
76-
tc := tc
77-
7876
t.Run(tc.name, func(t *testing.T) {
7977
t.Parallel()
8078

internal/cmd/run.go

-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
389389
var wg sync.WaitGroup
390390
wg.Add(len(ww))
391391
for _, w := range ww {
392-
w := w
393392
go func() {
394393
w()
395394
wg.Done()

internal/cmd/run_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ func TestRunScriptErrorsAndAbort(t *testing.T) {
231231
}
232232

233233
for _, tc := range testCases {
234-
tc := tc
235234
name := tc.testFilename
236235
if tc.name != "" {
237236
name = fmt.Sprintf("%s (%s)", tc.testFilename, tc.name)
@@ -299,8 +298,6 @@ func TestInvalidOptionsThresholdErrExitCode(t *testing.T) {
299298
}
300299

301300
for _, tc := range testCases {
302-
tc := tc
303-
304301
t.Run(tc.name, func(t *testing.T) {
305302
t.Parallel()
306303

@@ -349,8 +346,6 @@ func TestThresholdsRuntimeBehavior(t *testing.T) {
349346
}
350347

351348
for _, tc := range testCases {
352-
tc := tc
353-
354349
t.Run(tc.name, func(t *testing.T) {
355350
t.Parallel()
356351

internal/cmd/runtime_options_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ func TestRuntimeOptions(t *testing.T) {
458458
},
459459
}
460460
for name, tc := range runtimeOptionsTestCases {
461-
tc := tc
462461
t.Run(fmt.Sprintf("RuntimeOptions test '%s'", name), func(t *testing.T) {
463462
t.Parallel()
464463
testRuntimeOptionsCase(t, tc)

internal/cmd/tests/cmd_cloud_run_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ func TestCloudRunCommandIncompatibleFlags(t *testing.T) {
5454
}
5555

5656
for _, tc := range testCases {
57-
tc := tc
58-
5957
t.Run(tc.name, func(t *testing.T) {
6058
t.Parallel()
6159

internal/cmd/tests/cmd_run_grpc_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ func TestGRPCInputOutput(t *testing.T) {
9494
require.NoError(t, err)
9595

9696
for name, test := range tc {
97-
name := name
98-
test := test
99-
10097
t.Run(name, func(t *testing.T) {
10198
t.Parallel()
10299

internal/cmd/tests/cmd_run_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -1925,8 +1925,6 @@ func TestUIRenderOutput(t *testing.T) {
19251925
}
19261926

19271927
for _, tc := range tests {
1928-
tc := tc
1929-
19301928
t.Run(tc.expRender, func(t *testing.T) {
19311929
t.Parallel()
19321930

@@ -1960,8 +1958,6 @@ func TestUIRenderWebDashboard(t *testing.T) {
19601958
}
19611959

19621960
for _, tc := range tests {
1963-
tc := tc
1964-
19651961
t.Run(tc.expRender, func(t *testing.T) {
19661962
t.Parallel()
19671963

@@ -2004,8 +2000,6 @@ func TestRunStaticArchives(t *testing.T) {
20042000
}
20052001

20062002
for _, tc := range tests {
2007-
tc := tc
2008-
20092003
t.Run("Using "+tc.archive, func(t *testing.T) {
20102004
t.Parallel()
20112005

@@ -2038,8 +2032,6 @@ func TestBadLogOutput(t *testing.T) {
20382032
}
20392033

20402034
for name, tc := range cases {
2041-
name := name
2042-
tc := tc
20432035
t.Run(name, func(t *testing.T) {
20442036
t.Parallel()
20452037
ts := NewGlobalTestState(t)
@@ -2182,7 +2174,6 @@ func TestEventSystemError(t *testing.T) {
21822174
}
21832175

21842176
for _, tc := range testCases {
2185-
tc := tc
21862177
t.Run(tc.name, func(t *testing.T) {
21872178
t.Parallel()
21882179
ts := NewGlobalTestState(t)
@@ -2328,7 +2319,6 @@ func TestBrowserPermissions(t *testing.T) {
23282319
}
23292320

23302321
for _, tt := range tests {
2331-
tt := tt
23322322
t.Run(tt.name, func(t *testing.T) {
23332323
t.Parallel()
23342324
script := fmt.Sprintf(`

internal/cmd/tests/tests_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func TestRootCommand(t *testing.T) {
2222

2323
helptxt := "Usage:\n k6 [command]\n\nAvailable Commands"
2424
for name, args := range cases {
25-
name, args := name, args
2625
t.Run(name, func(t *testing.T) {
2726
t.Parallel()
2827
ts := NewGlobalTestState(t)

internal/cmd/ui_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ left 2 [ 0% ] right 2 000
6565
}
6666

6767
for _, tc := range testCases {
68-
tc := tc
6968
t.Run(tc.name, func(t *testing.T) {
7069
t.Parallel()
7170
pbs := createTestProgressBars(3, tc.padding, 1)

internal/ds/histogram/hdr_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ func TestHistogramAddWithSimpleValues(t *testing.T) {
122122
}
123123

124124
for i, tc := range cases {
125-
tc := tc
126125
t.Run(strconv.Itoa(i), func(t *testing.T) {
127126
t.Parallel()
128127
h := NewHdr()

internal/event/system_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func TestEventSystem(t *testing.T) {
8888
data int
8989
)
9090
for _, et := range emitEvents {
91-
et := et
9291
evt := &Event{Type: et, Data: data, Done: func() {
9392
doneMx.Lock()
9493
processed[et]++

internal/execution/scheduler_ext_exec_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ func TestExecutionInfoAll(t *testing.T) {
392392
}
393393

394394
for _, tc := range testCases {
395-
tc := tc
396395
t.Run(tc.name, func(t *testing.T) {
397396
t.Parallel()
398397

internal/execution/scheduler_ext_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func TestSchedulerRunNonDefault(t *testing.T) {
132132
}
133133

134134
for _, tc := range testCases {
135-
tc := tc
136135
t.Run(tc.name, func(t *testing.T) {
137136
t.Parallel()
138137
piState := getTestPreInitState(t)
@@ -247,7 +246,6 @@ func TestSchedulerRunEnv(t *testing.T) {
247246
}
248247

249248
for _, tc := range testCases {
250-
tc := tc
251249
t.Run(tc.name, func(t *testing.T) {
252250
t.Parallel()
253251
piState := getTestPreInitState(t)
@@ -462,7 +460,6 @@ func TestSchedulerRunCustomTags(t *testing.T) {
462460
}
463461

464462
for _, tc := range testCases {
465-
tc := tc
466463
t.Run(tc.name, func(t *testing.T) {
467464
t.Parallel()
468465
piState := getTestPreInitState(t)
@@ -843,7 +840,6 @@ func TestSchedulerStages(t *testing.T) {
843840
}
844841

845842
for name, data := range testdata {
846-
data := data
847843
t.Run(name, func(t *testing.T) {
848844
t.Parallel()
849845
runner := &minirunner.MiniRunner{
@@ -1099,7 +1095,6 @@ func TestDNSResolverCache(t *testing.T) {
10991095
}
11001096

11011097
for name, tc := range testCases {
1102-
tc := tc
11031098
t.Run(name, func(t *testing.T) {
11041099
t.Parallel()
11051100
logger := logrus.New()

0 commit comments

Comments
 (0)