Skip to content

Commit 01a9b3d

Browse files
golangci-lint: add copyloopvar linter and auto-fixes (#18829)
Signed-off-by: Tim Vaillancourt <[email protected]>
1 parent b9dbf79 commit 01a9b3d

File tree

15 files changed

+10
-22
lines changed

15 files changed

+10
-22
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ linters:
55
default: none
66
enable:
77
- bodyclose
8+
- copyloopvar
89
- depguard
910
- errcheck
1011
- govet

go/cmd/zk/internal/zkfs/zkfs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestFormatACL(t *testing.T) {
7575
}
7676

7777
for _, tc := range testCases {
78-
tc := tc
78+
7979
t.Run(tc.name, func(t *testing.T) {
8080
assert.Equal(t, tc.expected, FormatACL(tc.acl))
8181
})

go/test/endtoend/vtgate/foreignkey/stress/fk_stress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func waitForReplicationCatchup(t *testing.T) {
473473
primaryPos := getTabletPosition(t, primary)
474474
var wg sync.WaitGroup
475475
for _, replica := range []*cluster.Vttablet{replicaNoFK, replicaFK} {
476-
replica := replica
476+
477477
wg.Add(1)
478478
go func() {
479479
waitForReplicaCatchup(t, ctx, replica, primaryPos)

go/vt/mysqlctl/schema.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func (mysqld *Mysqld) GetSchema(ctx context.Context, dbName string, request *tab
114114
tableNames := make([]string, 0, len(tds))
115115
for _, td := range tds {
116116
tableNames = append(tableNames, td.Name)
117-
td := td
118117

119118
eg.Go(func() error {
120119
fields, columns, schema, err := mysqld.collectSchema(ctx, dbName, td.Name, td.Type, request.TableSchemaOnly)

go/vt/topo/keyspace.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ func (ts *Server) FindAllShardsInKeyspace(ctx context.Context, keyspace string,
301301
eg.SetLimit(int(opt.Concurrency))
302302

303303
for _, shard := range shards {
304-
shard := shard
305304

306305
eg.Go(func() error {
307306
si, err := ts.GetShard(ctx, keyspace, shard)

go/vt/topo/shard_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func TestValidateShardName(t *testing.T) {
350350
}
351351

352352
for _, tcase := range cases {
353-
tcase := tcase
353+
354354
t.Run(tcase.name, func(t *testing.T) {
355355
t.Parallel()
356356

go/vt/topo/topoproto/tablet_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ func TestIsTabletsInList(t *testing.T) {
118118
}
119119

120120
for _, testcase := range testcases {
121-
// We create an explicit copy of the range variable for each parallel runner
122-
// to be sure that they each run as expected. You can see more information on
123-
// this here: https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks
124-
testcase := testcase
125121
t.Run(testcase.name, func(t *testing.T) {
126122
t.Parallel()
127123
out := IsTabletInList(testcase.tablet, testcase.allTablets)

go/vt/vtadmin/cluster/cluster_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ func TestGetSchema(t *testing.T) {
16941694
ctx := context.Background()
16951695

16961696
for i, tt := range tests {
1697-
i := i
1697+
16981698
t.Run(tt.name, func(t *testing.T) {
16991699
t.Parallel()
17001700

go/vt/vtadmin/http/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestDeprecateQueryParam(t *testing.T) {
7272
}
7373

7474
for _, tcase := range cases {
75-
tcase := tcase
75+
7676
t.Run("", func(t *testing.T) {
7777
query := url.Values(tcase.in)
7878

go/vt/vtadmin/http/handlers/panic_recovery_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestPanicRecoveryHandler(t *testing.T) {
5555
}
5656

5757
for _, tcase := range cases {
58-
tcase := tcase
58+
5959
t.Run(tcase.route, func(t *testing.T) {
6060
rec := httptest.ResponseRecorder{
6161
Body: bytes.NewBuffer(nil),

0 commit comments

Comments
 (0)