Skip to content

Commit

Permalink
chore: Update golangci-lint linters and apply fixes (#1428)
Browse files Browse the repository at this point in the history
* Update to resolve lint errors

* Update linting configuration and remove for loop variable copies

* Ignore usetesting lint
  • Loading branch information
SBGoods authored Feb 18, 2025
1 parent a46ad95 commit 83d80f8
Show file tree
Hide file tree
Showing 14 changed files with 8 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ linters:
enable:
- durationcheck
- errcheck
- exportloopref
- copyloopvar
- gofmt
- gosimple
- ineffassign
Expand All @@ -20,7 +20,7 @@ linters:
# - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
- predeclared
- staticcheck
- tenv
- usetesting
- unconvert
- unparam
- unused
Expand Down
2 changes: 0 additions & 2 deletions helper/acctest/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func TestRandSSHKeyPair(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down
7 changes: 1 addition & 6 deletions helper/resource/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest"
Expand Down Expand Up @@ -78,8 +79,6 @@ func TestProtoV5ProviderFactoriesMerge(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -153,8 +152,6 @@ func TestProtoV6ProviderFactoriesMerge(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -228,8 +225,6 @@ func TestSdkProviderFactoriesMerge(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down
2 changes: 0 additions & 2 deletions helper/resource/testcase_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ provider "test" {}
}

for name, test := range tests {
name, test := name, test

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

Expand Down
5 changes: 1 addition & 4 deletions helper/resource/testcase_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -68,8 +69,6 @@ func TestTestCaseHasProviders(t *testing.T) {
}

for name, test := range tests {
name, test := name, test

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

Expand Down Expand Up @@ -148,8 +147,6 @@ func TestTestCaseValidate(t *testing.T) {
}

for name, test := range tests {
name, test := name, test

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

Expand Down
8 changes: 0 additions & 8 deletions helper/resource/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,6 @@ func TestTestCheckResourceAttr(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -1834,8 +1832,6 @@ func TestTestCheckResourceAttrWith(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -2065,8 +2061,6 @@ func TestTestCheckNoResourceAttr(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -2495,8 +2489,6 @@ func TestTestCheckResourceAttrSet(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down
6 changes: 0 additions & 6 deletions helper/resource/teststep_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ resource "test_test" "test" {}
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -747,8 +745,6 @@ resource "test_test" "test" {}
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -962,8 +958,6 @@ provider "test" {}
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down
4 changes: 0 additions & 4 deletions helper/resource/teststep_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ func TestTestStepHasProviders(t *testing.T) {
}

for name, test := range tests {
name, test := name, test

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

Expand Down Expand Up @@ -193,8 +191,6 @@ func TestTestStepValidate(t *testing.T) {
}

for name, test := range tests {
name, test := name, test

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

Expand Down
26 changes: 0 additions & 26 deletions helper/schema/grpc_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3268,8 +3268,6 @@ func TestGRPCProviderServerConfigureProvider(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -3389,8 +3387,6 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -3470,8 +3466,6 @@ func TestGRPCProviderServerMoveResourceState(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -3953,8 +3947,6 @@ func TestGRPCProviderServerValidateResourceTypeConfig(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -4838,8 +4830,6 @@ func TestReadResource(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()
resp, err := testCase.server.ReadResource(context.Background(), testCase.req)
Expand Down Expand Up @@ -5560,8 +5550,6 @@ func TestPlanResourceChange(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -5871,8 +5859,6 @@ func TestApplyResourceChange(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -6014,8 +6000,6 @@ func TestApplyResourceChange_ResourceFuncs(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -6148,7 +6132,6 @@ func TestApplyResourceChange_bigint(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Description, func(t *testing.T) {
server := NewGRPCProviderServer(&Provider{
ResourcesMap: map[string]*Resource{
Expand Down Expand Up @@ -6376,8 +6359,6 @@ func TestApplyResourceChange_ResourceFuncs_writeOnly(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down Expand Up @@ -6710,8 +6691,6 @@ func TestImportResourceState(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()
resp, err := testCase.server.ImportResourceState(context.Background(), testCase.req)
Expand Down Expand Up @@ -7366,8 +7345,6 @@ func TestReadDataSource(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()
resp, err := testCase.server.ReadDataSource(context.Background(), testCase.req)
Expand Down Expand Up @@ -8138,7 +8115,6 @@ func TestStopContext_grpc(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Description, func(t *testing.T) {
server := NewGRPCProviderServer(&Provider{
ResourcesMap: map[string]*Resource{
Expand Down Expand Up @@ -8253,7 +8229,6 @@ func TestStopContext_stop(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Description, func(t *testing.T) {
server := NewGRPCProviderServer(&Provider{
ResourcesMap: map[string]*Resource{
Expand Down Expand Up @@ -8371,7 +8346,6 @@ func TestStopContext_stopReset(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Description, func(t *testing.T) {
server := NewGRPCProviderServer(&Provider{
ResourcesMap: map[string]*Resource{
Expand Down
4 changes: 1 addition & 3 deletions helper/schema/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,6 @@ func TestProviderConfigure(t *testing.T) {
}

for name, tc := range cases {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2246,8 +2245,6 @@ func TestProviderImportState(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

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

func TestProviderUserAgentAppendViaEnvVar(t *testing.T) {
if oldenv, isSet := os.LookupEnv(uaEnvVar); isSet {
//nolint:usetesting
defer os.Setenv(uaEnvVar, oldenv)
} else {
defer os.Unsetenv(uaEnvVar)
Expand Down
2 changes: 0 additions & 2 deletions helper/structure/suppress_json_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func TestSuppressJsonDiff(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down
3 changes: 1 addition & 2 deletions helper/validation/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/hashicorp/go-cty/cty"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -240,8 +241,6 @@ func TestToDiagFunc(t *testing.T) {
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

Expand Down
4 changes: 0 additions & 4 deletions internal/configs/hcl2shim/flatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ func TestFlatmapValueFromHCL2(t *testing.T) {
}

for _, test := range tests {
test := test

t.Run(test.Value.GoString(), func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -312,8 +310,6 @@ func TestFlatmapValueFromHCL2FromFlatmap(t *testing.T) {
}

for _, test := range tests {
test := test

t.Run(test.Name, func(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 2 additions & 1 deletion internal/plugin/convert/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/logging"
)
Expand Down Expand Up @@ -136,7 +137,7 @@ func AttributePathToPath(ap *tftypes.AttributePath) cty.Path {

// PathToAttributePath takes a cty.Path and converts it to a proto-encoded path.
func PathToAttributePath(p cty.Path) *tftypes.AttributePath {
if p == nil || len(p) < 1 {
if len(p) < 1 {
return nil
}
ap := tftypes.NewAttributePath()
Expand Down

0 comments on commit 83d80f8

Please sign in to comment.