Skip to content

Commit

Permalink
tests/provider: Enable staticcheck S1034 check
Browse files Browse the repository at this point in the history
Reference: hashicorp#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) {
                       ^
```
  • Loading branch information
bflad committed Apr 12, 2019
1 parent de2b291 commit 0a4d6d7
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions aws/iam_policy_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
6 changes: 3 additions & 3 deletions aws/resource_aws_iam_server_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
12 changes: 6 additions & 6 deletions aws/resource_aws_opsworks_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand All @@ -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 ""
}
Expand All @@ -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 ""
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_spot_fleet_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
3 changes: 1 addition & 2 deletions staticcheck.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ checks = [
"-ST1000",
"-ST1003",
"-ST1005",
"-ST1012",
"-S1034"
"-ST1012"
]

0 comments on commit 0a4d6d7

Please sign in to comment.