From 0a4d6d7bab6972dc443395e8264b7867f579a45f Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 11 Apr 2019 21:42:59 -0400 Subject: [PATCH] tests/provider: Enable staticcheck S1034 check Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/7243 Previous output from linter: ``` aws/iam_policy_model.go:180:11: S1034: assigning the result of this type assertion to a variable (switch var_values := var_values.(type)) could eliminate the following type assertions: aws/iam_policy_model.go:182:103 (gosimple) switch var_values.(type) { ^ aws/resource_aws_iam_server_certificate.go:218:9: S1034: assigning the result of this type assertion to a variable (switch cert := cert.(type)) could eliminate the following type assertions: aws/resource_aws_iam_server_certificate.go:220:13 aws/resource_aws_iam_server_certificate.go:222:14 (gosimple) switch cert.(type) { ^ aws/resource_aws_instance.go:139:13: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_instance.go:141:30 (gosimple) switch v.(type) { ^ aws/resource_aws_key_pair.go:50:13: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_key_pair.go:52:32 (gosimple) switch v.(type) { ^ aws/resource_aws_launch_configuration.go:76:13: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_launch_configuration.go:78:30 (gosimple) switch v.(type) { ^ aws/resource_aws_opsworks_application.go:171:16: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_opsworks_application.go:173:35 (gosimple) switch v.(type) { ^ aws/resource_aws_opsworks_application.go:184:16: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_opsworks_application.go:186:35 (gosimple) switch v.(type) { ^ aws/resource_aws_opsworks_application.go:196:16: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_opsworks_application.go:198:35 (gosimple) switch v.(type) { ^ aws/resource_aws_s3_bucket.go:2283:10: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_s3_bucket.go:2285:30 (gosimple) switch v.(type) { ^ aws/resource_aws_security_group.go:1340:9: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_security_group.go:1342:25 (gosimple) switch v.(type) { ^ aws/resource_aws_spot_fleet_request.go:242:16: S1034: assigning the result of this type assertion to a variable (switch v := v.(type)) could eliminate the following type assertions: aws/resource_aws_spot_fleet_request.go:244:33 (gosimple) switch v.(type) { ^ ``` --- aws/iam_policy_model.go | 6 +++--- aws/resource_aws_iam_server_certificate.go | 6 +++--- aws/resource_aws_instance.go | 4 ++-- aws/resource_aws_key_pair.go | 4 ++-- aws/resource_aws_launch_configuration.go | 4 ++-- aws/resource_aws_opsworks_application.go | 12 ++++++------ aws/resource_aws_s3_bucket.go | 4 ++-- aws/resource_aws_security_group.go | 4 ++-- aws/resource_aws_spot_fleet_request.go | 4 ++-- staticcheck.conf | 3 +-- 10 files changed, 25 insertions(+), 26 deletions(-) diff --git a/aws/iam_policy_model.go b/aws/iam_policy_model.go index 4bb627955dcd..8726c082663b 100644 --- a/aws/iam_policy_model.go +++ b/aws/iam_policy_model.go @@ -177,12 +177,12 @@ func (cs *IAMPolicyStatementConditionSet) UnmarshalJSON(b []byte) error { for test_key, test_value := range data { for var_key, var_values := range test_value { - switch var_values.(type) { + switch var_values := var_values.(type) { case string: - out = append(out, IAMPolicyStatementCondition{Test: test_key, Variable: var_key, Values: []string{var_values.(string)}}) + out = append(out, IAMPolicyStatementCondition{Test: test_key, Variable: var_key, Values: []string{var_values}}) case []interface{}: values := []string{} - for _, v := range var_values.([]interface{}) { + for _, v := range var_values { values = append(values, v.(string)) } out = append(out, IAMPolicyStatementCondition{Test: test_key, Variable: var_key, Values: values}) diff --git a/aws/resource_aws_iam_server_certificate.go b/aws/resource_aws_iam_server_certificate.go index e3402f032159..644789ce8ffb 100644 --- a/aws/resource_aws_iam_server_certificate.go +++ b/aws/resource_aws_iam_server_certificate.go @@ -215,11 +215,11 @@ func normalizeCert(cert interface{}) string { } var rawCert string - switch cert.(type) { + switch cert := cert.(type) { case string: - rawCert = cert.(string) + rawCert = cert case *string: - rawCert = *cert.(*string) + rawCert = *cert default: return "" } diff --git a/aws/resource_aws_instance.go b/aws/resource_aws_instance.go index 21635731d867..4d39a9ab2a36 100644 --- a/aws/resource_aws_instance.go +++ b/aws/resource_aws_instance.go @@ -136,9 +136,9 @@ func resourceAwsInstance() *schema.Resource { return false }, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return userDataHashSum(v.(string)) + return userDataHashSum(v) default: return "" } diff --git a/aws/resource_aws_key_pair.go b/aws/resource_aws_key_pair.go index 48f954b9cca5..2fc2476397d5 100644 --- a/aws/resource_aws_key_pair.go +++ b/aws/resource_aws_key_pair.go @@ -47,9 +47,9 @@ func resourceAwsKeyPair() *schema.Resource { Required: true, ForceNew: true, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return strings.TrimSpace(v.(string)) + return strings.TrimSpace(v) default: return "" } diff --git a/aws/resource_aws_launch_configuration.go b/aws/resource_aws_launch_configuration.go index c72376566d7e..68ab22f61ac2 100644 --- a/aws/resource_aws_launch_configuration.go +++ b/aws/resource_aws_launch_configuration.go @@ -73,9 +73,9 @@ func resourceAwsLaunchConfiguration() *schema.Resource { ForceNew: true, ConflictsWith: []string{"user_data_base64"}, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return userDataHashSum(v.(string)) + return userDataHashSum(v) default: return "" } diff --git a/aws/resource_aws_opsworks_application.go b/aws/resource_aws_opsworks_application.go index ef983b6a4928..224bde4ba1ef 100644 --- a/aws/resource_aws_opsworks_application.go +++ b/aws/resource_aws_opsworks_application.go @@ -168,9 +168,9 @@ func resourceAwsOpsworksApplication() *schema.Resource { Type: schema.TypeString, Required: true, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return strings.TrimSpace(v.(string)) + return strings.TrimSpace(v) default: return "" } @@ -181,9 +181,9 @@ func resourceAwsOpsworksApplication() *schema.Resource { Required: true, Sensitive: true, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return strings.TrimSpace(v.(string)) + return strings.TrimSpace(v) default: return "" } @@ -193,9 +193,9 @@ func resourceAwsOpsworksApplication() *schema.Resource { Type: schema.TypeString, Optional: true, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return strings.TrimSpace(v.(string)) + return strings.TrimSpace(v) default: return "" } diff --git a/aws/resource_aws_s3_bucket.go b/aws/resource_aws_s3_bucket.go index 4212a4acda39..c8c75e81ce71 100644 --- a/aws/resource_aws_s3_bucket.go +++ b/aws/resource_aws_s3_bucket.go @@ -2280,9 +2280,9 @@ func removeNil(data map[string]interface{}) map[string]interface{} { continue } - switch v.(type) { + switch v := v.(type) { case map[string]interface{}: - withoutNil[k] = removeNil(v.(map[string]interface{})) + withoutNil[k] = removeNil(v) default: withoutNil[k] = v } diff --git a/aws/resource_aws_security_group.go b/aws/resource_aws_security_group.go index 0ea62cc2057a..887786bc8351 100644 --- a/aws/resource_aws_security_group.go +++ b/aws/resource_aws_security_group.go @@ -1337,9 +1337,9 @@ func idHash(rType, protocol string, toPort, fromPort int64, self bool) string { // protocolStateFunc ensures we only store a string in any protocol field func protocolStateFunc(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - p := protocolForValue(v.(string)) + p := protocolForValue(v) return p default: log.Printf("[WARN] Non String value given for Protocol: %#v", v) diff --git a/aws/resource_aws_spot_fleet_request.go b/aws/resource_aws_spot_fleet_request.go index a145b648408a..f5024f20d9e4 100644 --- a/aws/resource_aws_spot_fleet_request.go +++ b/aws/resource_aws_spot_fleet_request.go @@ -239,9 +239,9 @@ func resourceAwsSpotFleetRequest() *schema.Resource { Optional: true, ForceNew: true, StateFunc: func(v interface{}) string { - switch v.(type) { + switch v := v.(type) { case string: - return userDataHashSum(v.(string)) + return userDataHashSum(v) default: return "" } diff --git a/staticcheck.conf b/staticcheck.conf index 1a44a902e146..bc226ad70d6b 100644 --- a/staticcheck.conf +++ b/staticcheck.conf @@ -5,6 +5,5 @@ checks = [ "-ST1000", "-ST1003", "-ST1005", - "-ST1012", - "-S1034" + "-ST1012" ]