Skip to content

Commit db56379

Browse files
authored
Enable staticcheck linter and fix issues (#879)
Reference: #865 Reference: https://www.terraform.io/language/settings/backends/local#path The removal of the deprecated `refresh` command `-state` flag in the acceptance testing framework should be safe as this is the default state location.
1 parent a4bd8e3 commit db56379

File tree

8 files changed

+14
-22
lines changed

8 files changed

+14
-22
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ linters:
2020
- nilerr
2121
# - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
2222
- predeclared
23-
# - staticcheck # TODO: https://github.com/hashicorp/terraform-plugin-sdk/issues/865
23+
- staticcheck
2424
# - tenv # TODO: Enable when upgrading Go 1.16 to 1.17
2525
- unconvert
2626
- unparam

helper/resource/testing_new_import_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func testStepNewImportState(t testing.T, c TestCase, helper *plugintest.Helper,
144144
break
145145
}
146146
}
147-
if oldR == nil {
147+
if oldR == nil || oldR.Primary == nil {
148148
t.Fatalf(
149149
"Failed state verification, resource with ID %s not found",
150150
r.Primary.ID)

helper/schema/resource_timeout.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ func (t *ResourceTimeout) ConfigDecode(s *Resource, c *terraform.ResourceConfig)
137137

138138
*timeout = rt
139139
}
140-
return nil
140+
141+
// This early return, which makes this function handle a single
142+
// timeout configuration block, should likely not be here but the
143+
// SDK has never raised an error for multiple blocks nor made any
144+
// precedence decisions for them in the past.
145+
// It is left here for compatibility reasons.
146+
return nil //nolint:staticcheck
141147
}
142148
}
143149

helper/schema/schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3088,7 +3088,7 @@ func TestSchemaMap_Diff(t *testing.T) {
30883088
"stream_enabled": false,
30893089
"stream_view_type": "",
30903090
},
3091-
CustomizeDiff: func(_ context.Context, diff *ResourceDiff, v interface{}) error {
3091+
CustomizeDiff: func(_ context.Context, diff *ResourceDiff, _ interface{}) error {
30923092
v, ok := diff.GetOk("unrelated_set")
30933093
if ok {
30943094
return fmt.Errorf("Didn't expect unrelated_set: %#v", v)

helper/schema/shims_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3343,7 +3343,7 @@ func TestShimSchemaMap_Diff(t *testing.T) {
33433343
"stream_enabled": false,
33443344
"stream_view_type": "",
33453345
},
3346-
CustomizeDiff: func(_ context.Context, diff *ResourceDiff, v interface{}) error {
3346+
CustomizeDiff: func(_ context.Context, diff *ResourceDiff, _ interface{}) error {
33473347
v, ok := diff.GetOk("unrelated_set")
33483348
if ok {
33493349
return fmt.Errorf("Didn't expect unrelated_set: %#v", v)

helper/validation/strings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func StringInSlice(valid []string, ignoreCase bool) schema.SchemaValidateFunc {
138138
}
139139

140140
for _, str := range valid {
141-
if v == str || (ignoreCase && strings.ToLower(v) == strings.ToLower(str)) {
141+
if v == str || (ignoreCase && strings.EqualFold(v, str)) {
142142
return warnings, errors
143143
}
144144
}
@@ -160,7 +160,7 @@ func StringNotInSlice(invalid []string, ignoreCase bool) schema.SchemaValidateFu
160160
}
161161

162162
for _, str := range invalid {
163-
if v == str || (ignoreCase && strings.ToLower(v) == strings.ToLower(str)) {
163+
if v == str || (ignoreCase && strings.EqualFold(v, str)) {
164164
errors = append(errors, fmt.Errorf("expected %s to not be any of %v, got %s", k, invalid, v))
165165
return warnings, errors
166166
}

internal/plugintest/working_dir.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (wd *WorkingDir) Import(resource, id string) error {
243243

244244
// Refresh runs terraform refresh
245245
func (wd *WorkingDir) Refresh() error {
246-
return wd.tf.Refresh(context.Background(), tfexec.Reattach(wd.reattachInfo), tfexec.State(filepath.Join(wd.baseDir, "terraform.tfstate")))
246+
return wd.tf.Refresh(context.Background(), tfexec.Reattach(wd.reattachInfo))
247247
}
248248

249249
// Schemas returns an object describing the provider schemas.

terraform/state.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,6 @@ func (s *State) removeInstance(r *ResourceState, v *InstanceState) {
421421
r.Primary = nil
422422
return
423423
}
424-
425-
// Check lists
426-
lists := [][]*InstanceState{r.Deposed}
427-
for _, is := range lists {
428-
for i, instance := range is {
429-
if instance == v {
430-
// Found it, remove it
431-
is, is[len(is)-1] = append(is[:i], is[i+1:]...), nil
432-
433-
// Done
434-
return
435-
}
436-
}
437-
}
438424
}
439425

440426
// RootModule returns the ModuleState for the root module

0 commit comments

Comments
 (0)