Skip to content

Commit 83d80f8

Browse files
authored
chore: Update golangci-lint linters and apply fixes (#1428)
* Update to resolve lint errors * Update linting configuration and remove for loop variable copies * Ignore usetesting lint
1 parent a46ad95 commit 83d80f8

14 files changed

+8
-72
lines changed

.golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ linters:
1111
enable:
1212
- durationcheck
1313
- errcheck
14-
- exportloopref
14+
- copyloopvar
1515
- gofmt
1616
- gosimple
1717
- ineffassign
@@ -20,7 +20,7 @@ linters:
2020
# - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
2121
- predeclared
2222
- staticcheck
23-
- tenv
23+
- usetesting
2424
- unconvert
2525
- unparam
2626
- unused

helper/acctest/random_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ func TestRandSSHKeyPair(t *testing.T) {
9191
}
9292

9393
for name, testCase := range testCases {
94-
name, testCase := name, testCase
95-
9694
t.Run(name, func(t *testing.T) {
9795
t.Parallel()
9896

helper/resource/plugin_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
1414
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
15+
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1617
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest"
@@ -78,8 +79,6 @@ func TestProtoV5ProviderFactoriesMerge(t *testing.T) {
7879
}
7980

8081
for name, testCase := range testCases {
81-
name, testCase := name, testCase
82-
8382
t.Run(name, func(t *testing.T) {
8483
t.Parallel()
8584

@@ -153,8 +152,6 @@ func TestProtoV6ProviderFactoriesMerge(t *testing.T) {
153152
}
154153

155154
for name, testCase := range testCases {
156-
name, testCase := name, testCase
157-
158155
t.Run(name, func(t *testing.T) {
159156
t.Parallel()
160157

@@ -228,8 +225,6 @@ func TestSdkProviderFactoriesMerge(t *testing.T) {
228225
}
229226

230227
for name, testCase := range testCases {
231-
name, testCase := name, testCase
232-
233228
t.Run(name, func(t *testing.T) {
234229
t.Parallel()
235230

helper/resource/testcase_providers_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ provider "test" {}
226226
}
227227

228228
for name, test := range tests {
229-
name, test := name, test
230-
231229
t.Run(name, func(t *testing.T) {
232230
t.Parallel()
233231

helper/resource/testcase_validate_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
1313
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
14+
1415
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1516
)
1617

@@ -68,8 +69,6 @@ func TestTestCaseHasProviders(t *testing.T) {
6869
}
6970

7071
for name, test := range tests {
71-
name, test := name, test
72-
7372
t.Run(name, func(t *testing.T) {
7473
t.Parallel()
7574

@@ -148,8 +147,6 @@ func TestTestCaseValidate(t *testing.T) {
148147
}
149148

150149
for name, test := range tests {
151-
name, test := name, test
152-
153150
t.Run(name, func(t *testing.T) {
154151
t.Parallel()
155152

helper/resource/testing_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,6 @@ func TestTestCheckResourceAttr(t *testing.T) {
14011401
}
14021402

14031403
for name, testCase := range testCases {
1404-
name, testCase := name, testCase
1405-
14061404
t.Run(name, func(t *testing.T) {
14071405
t.Parallel()
14081406

@@ -1834,8 +1832,6 @@ func TestTestCheckResourceAttrWith(t *testing.T) {
18341832
}
18351833

18361834
for name, testCase := range testCases {
1837-
name, testCase := name, testCase
1838-
18391835
t.Run(name, func(t *testing.T) {
18401836
t.Parallel()
18411837

@@ -2065,8 +2061,6 @@ func TestTestCheckNoResourceAttr(t *testing.T) {
20652061
}
20662062

20672063
for name, testCase := range testCases {
2068-
name, testCase := name, testCase
2069-
20702064
t.Run(name, func(t *testing.T) {
20712065
t.Parallel()
20722066

@@ -2495,8 +2489,6 @@ func TestTestCheckResourceAttrSet(t *testing.T) {
24952489
}
24962490

24972491
for name, testCase := range testCases {
2498-
name, testCase := name, testCase
2499-
25002492
t.Run(name, func(t *testing.T) {
25012493
t.Parallel()
25022494

helper/resource/teststep_providers_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ resource "test_test" "test" {}
115115
}
116116

117117
for name, testCase := range testCases {
118-
name, testCase := name, testCase
119-
120118
t.Run(name, func(t *testing.T) {
121119
t.Parallel()
122120

@@ -747,8 +745,6 @@ resource "test_test" "test" {}
747745
}
748746

749747
for name, testCase := range testCases {
750-
name, testCase := name, testCase
751-
752748
t.Run(name, func(t *testing.T) {
753749
t.Parallel()
754750

@@ -962,8 +958,6 @@ provider "test" {}
962958
}
963959

964960
for name, testCase := range testCases {
965-
name, testCase := name, testCase
966-
967961
t.Run(name, func(t *testing.T) {
968962
t.Parallel()
969963

helper/resource/teststep_validate_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ func TestTestStepHasProviders(t *testing.T) {
6161
}
6262

6363
for name, test := range tests {
64-
name, test := name, test
65-
6664
t.Run(name, func(t *testing.T) {
6765
t.Parallel()
6866

@@ -193,8 +191,6 @@ func TestTestStepValidate(t *testing.T) {
193191
}
194192

195193
for name, test := range tests {
196-
name, test := name, test
197-
198194
t.Run(name, func(t *testing.T) {
199195
t.Parallel()
200196

helper/schema/grpc_provider_test.go

-26
Original file line numberDiff line numberDiff line change
@@ -3268,8 +3268,6 @@ func TestGRPCProviderServerConfigureProvider(t *testing.T) {
32683268
}
32693269

32703270
for name, testCase := range testCases {
3271-
name, testCase := name, testCase
3272-
32733271
t.Run(name, func(t *testing.T) {
32743272
t.Parallel()
32753273

@@ -3389,8 +3387,6 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
33893387
}
33903388

33913389
for name, testCase := range testCases {
3392-
name, testCase := name, testCase
3393-
33943390
t.Run(name, func(t *testing.T) {
33953391
t.Parallel()
33963392

@@ -3470,8 +3466,6 @@ func TestGRPCProviderServerMoveResourceState(t *testing.T) {
34703466
}
34713467

34723468
for name, testCase := range testCases {
3473-
name, testCase := name, testCase
3474-
34753469
t.Run(name, func(t *testing.T) {
34763470
t.Parallel()
34773471

@@ -3953,8 +3947,6 @@ func TestGRPCProviderServerValidateResourceTypeConfig(t *testing.T) {
39533947
}
39543948

39553949
for name, testCase := range testCases {
3956-
name, testCase := name, testCase
3957-
39583950
t.Run(name, func(t *testing.T) {
39593951
t.Parallel()
39603952

@@ -4838,8 +4830,6 @@ func TestReadResource(t *testing.T) {
48384830
}
48394831

48404832
for name, testCase := range testCases {
4841-
name, testCase := name, testCase
4842-
48434833
t.Run(name, func(t *testing.T) {
48444834
t.Parallel()
48454835
resp, err := testCase.server.ReadResource(context.Background(), testCase.req)
@@ -5560,8 +5550,6 @@ func TestPlanResourceChange(t *testing.T) {
55605550
}
55615551

55625552
for name, testCase := range testCases {
5563-
name, testCase := name, testCase
5564-
55655553
t.Run(name, func(t *testing.T) {
55665554
t.Parallel()
55675555

@@ -5871,8 +5859,6 @@ func TestApplyResourceChange(t *testing.T) {
58715859
}
58725860

58735861
for name, testCase := range testCases {
5874-
name, testCase := name, testCase
5875-
58765862
t.Run(name, func(t *testing.T) {
58775863
t.Parallel()
58785864

@@ -6014,8 +6000,6 @@ func TestApplyResourceChange_ResourceFuncs(t *testing.T) {
60146000
}
60156001

60166002
for name, testCase := range testCases {
6017-
name, testCase := name, testCase
6018-
60196003
t.Run(name, func(t *testing.T) {
60206004
t.Parallel()
60216005

@@ -6148,7 +6132,6 @@ func TestApplyResourceChange_bigint(t *testing.T) {
61486132
}
61496133

61506134
for _, testCase := range testCases {
6151-
testCase := testCase
61526135
t.Run(testCase.Description, func(t *testing.T) {
61536136
server := NewGRPCProviderServer(&Provider{
61546137
ResourcesMap: map[string]*Resource{
@@ -6376,8 +6359,6 @@ func TestApplyResourceChange_ResourceFuncs_writeOnly(t *testing.T) {
63766359
}
63776360

63786361
for name, testCase := range testCases {
6379-
name, testCase := name, testCase
6380-
63816362
t.Run(name, func(t *testing.T) {
63826363
t.Parallel()
63836364

@@ -6710,8 +6691,6 @@ func TestImportResourceState(t *testing.T) {
67106691
}
67116692

67126693
for name, testCase := range testCases {
6713-
name, testCase := name, testCase
6714-
67156694
t.Run(name, func(t *testing.T) {
67166695
t.Parallel()
67176696
resp, err := testCase.server.ImportResourceState(context.Background(), testCase.req)
@@ -7366,8 +7345,6 @@ func TestReadDataSource(t *testing.T) {
73667345
}
73677346

73687347
for name, testCase := range testCases {
7369-
name, testCase := name, testCase
7370-
73717348
t.Run(name, func(t *testing.T) {
73727349
t.Parallel()
73737350
resp, err := testCase.server.ReadDataSource(context.Background(), testCase.req)
@@ -8138,7 +8115,6 @@ func TestStopContext_grpc(t *testing.T) {
81388115
}
81398116

81408117
for _, testCase := range testCases {
8141-
testCase := testCase
81428118
t.Run(testCase.Description, func(t *testing.T) {
81438119
server := NewGRPCProviderServer(&Provider{
81448120
ResourcesMap: map[string]*Resource{
@@ -8253,7 +8229,6 @@ func TestStopContext_stop(t *testing.T) {
82538229
}
82548230

82558231
for _, testCase := range testCases {
8256-
testCase := testCase
82578232
t.Run(testCase.Description, func(t *testing.T) {
82588233
server := NewGRPCProviderServer(&Provider{
82598234
ResourcesMap: map[string]*Resource{
@@ -8371,7 +8346,6 @@ func TestStopContext_stopReset(t *testing.T) {
83718346
}
83728347

83738348
for _, testCase := range testCases {
8374-
testCase := testCase
83758349
t.Run(testCase.Description, func(t *testing.T) {
83768350
server := NewGRPCProviderServer(&Provider{
83778351
ResourcesMap: map[string]*Resource{

helper/schema/provider_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,6 @@ func TestProviderConfigure(t *testing.T) {
16331633
}
16341634

16351635
for name, tc := range cases {
1636-
name, tc := name, tc
16371636
t.Run(name, func(t *testing.T) {
16381637
t.Parallel()
16391638

@@ -2246,8 +2245,6 @@ func TestProviderImportState(t *testing.T) {
22462245
}
22472246

22482247
for name, testCase := range testCases {
2249-
name, testCase := name, testCase
2250-
22512248
t.Run(name, func(t *testing.T) {
22522249
t.Parallel()
22532250

@@ -2501,6 +2498,7 @@ func TestProvider_InternalValidate(t *testing.T) {
25012498

25022499
func TestProviderUserAgentAppendViaEnvVar(t *testing.T) {
25032500
if oldenv, isSet := os.LookupEnv(uaEnvVar); isSet {
2501+
//nolint:usetesting
25042502
defer os.Setenv(uaEnvVar, oldenv)
25052503
} else {
25062504
defer os.Unsetenv(uaEnvVar)

helper/structure/suppress_json_diff_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func TestSuppressJsonDiff(t *testing.T) {
4040
}
4141

4242
for name, testCase := range testCases {
43-
name, testCase := name, testCase
44-
4543
t.Run(name, func(t *testing.T) {
4644
t.Parallel()
4745

helper/validation/meta_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/hashicorp/go-cty/cty"
11+
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1213
)
1314

@@ -240,8 +241,6 @@ func TestToDiagFunc(t *testing.T) {
240241
}
241242

242243
for name, testCase := range testCases {
243-
name, testCase := name, testCase
244-
245244
t.Run(name, func(t *testing.T) {
246245
t.Parallel()
247246

internal/configs/hcl2shim/flatmap_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ func TestFlatmapValueFromHCL2(t *testing.T) {
243243
}
244244

245245
for _, test := range tests {
246-
test := test
247-
248246
t.Run(test.Value.GoString(), func(t *testing.T) {
249247
t.Parallel()
250248

@@ -312,8 +310,6 @@ func TestFlatmapValueFromHCL2FromFlatmap(t *testing.T) {
312310
}
313311

314312
for _, test := range tests {
315-
test := test
316-
317313
t.Run(test.Name, func(t *testing.T) {
318314
t.Parallel()
319315

internal/plugin/convert/diagnostics.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
1212
"github.com/hashicorp/terraform-plugin-go/tftypes"
13+
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1415
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/logging"
1516
)
@@ -136,7 +137,7 @@ func AttributePathToPath(ap *tftypes.AttributePath) cty.Path {
136137

137138
// PathToAttributePath takes a cty.Path and converts it to a proto-encoded path.
138139
func PathToAttributePath(p cty.Path) *tftypes.AttributePath {
139-
if p == nil || len(p) < 1 {
140+
if len(p) < 1 {
140141
return nil
141142
}
142143
ap := tftypes.NewAttributePath()

0 commit comments

Comments
 (0)