Skip to content

Commit ea6c32e

Browse files
committed
Resolve linter errors and warnings
1 parent 159572f commit ea6c32e

File tree

8 files changed

+46
-45
lines changed

8 files changed

+46
-45
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ linters:
2424
- unconvert
2525
- unparam
2626
- unused
27-
- vet
27+
- govet
2828

2929
run:
3030
# Prevent false positive timeouts in CI

helper/acctest/random.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func RandomWithPrefix(name string) string {
3434
return fmt.Sprintf("%s-%d", name, RandInt())
3535
}
3636

37-
// RandIntRange returns a random integer between min (inclusive) and max (exclusive)
38-
func RandIntRange(min int, max int) int {
39-
return rand.Intn(max-min) + min
37+
// RandIntRange returns a random integer between minVal (inclusive) and maxVal (exclusive)
38+
func RandIntRange(minVal int, maxVal int) int {
39+
return rand.Intn(maxVal-minVal) + minVal
4040
}
4141

4242
// RandString generates a random alphanumeric string of the length specified

helper/schema/shims_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func testApplyDiff(t *testing.T,
8181
}
8282

8383
if !cmp.Equal(expectedState, newState, equateEmpty, typeComparer, valueComparer) {
84-
t.Fatalf(cmp.Diff(expectedState, newState, equateEmpty, typeComparer, valueComparer))
84+
t.Fatal(cmp.Diff(expectedState, newState, equateEmpty, typeComparer, valueComparer))
8585
}
8686
}
8787

helper/validation/float.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
)
1111

1212
// FloatBetween returns a SchemaValidateFunc which tests if the provided value
13-
// is of type float64 and is between min and max (inclusive).
14-
func FloatBetween(min, max float64) schema.SchemaValidateFunc {
13+
// is of type float64 and is between minVal and maxVal (inclusive).
14+
func FloatBetween(minVal, maxVal float64) schema.SchemaValidateFunc {
1515
return func(i interface{}, k string) (s []string, es []error) {
1616
v, ok := i.(float64)
1717
if !ok {
1818
es = append(es, fmt.Errorf("expected type of %s to be float64", k))
1919
return
2020
}
2121

22-
if v < min || v > max {
23-
es = append(es, fmt.Errorf("expected %s to be in the range (%f - %f), got %f", k, min, max, v))
22+
if v < minVal || v > maxVal {
23+
es = append(es, fmt.Errorf("expected %s to be in the range (%f - %f), got %f", k, minVal, maxVal, v))
2424
return
2525
}
2626

@@ -29,17 +29,17 @@ func FloatBetween(min, max float64) schema.SchemaValidateFunc {
2929
}
3030

3131
// FloatAtLeast returns a SchemaValidateFunc which tests if the provided value
32-
// is of type float and is at least min (inclusive)
33-
func FloatAtLeast(min float64) schema.SchemaValidateFunc {
32+
// is of type float and is at least minVal (inclusive)
33+
func FloatAtLeast(minVal float64) schema.SchemaValidateFunc {
3434
return func(i interface{}, k string) (s []string, es []error) {
3535
v, ok := i.(float64)
3636
if !ok {
3737
es = append(es, fmt.Errorf("expected type of %s to be float", k))
3838
return
3939
}
4040

41-
if v < min {
42-
es = append(es, fmt.Errorf("expected %s to be at least (%f), got %f", k, min, v))
41+
if v < minVal {
42+
es = append(es, fmt.Errorf("expected %s to be at least (%f), got %f", k, minVal, v))
4343
return
4444
}
4545

@@ -48,17 +48,17 @@ func FloatAtLeast(min float64) schema.SchemaValidateFunc {
4848
}
4949

5050
// FloatAtMost returns a SchemaValidateFunc which tests if the provided value
51-
// is of type float and is at most max (inclusive)
52-
func FloatAtMost(max float64) schema.SchemaValidateFunc {
51+
// is of type float and is at most maxVal (inclusive)
52+
func FloatAtMost(maxVal float64) schema.SchemaValidateFunc {
5353
return func(i interface{}, k string) (s []string, es []error) {
5454
v, ok := i.(float64)
5555
if !ok {
5656
es = append(es, fmt.Errorf("expected type of %s to be float", k))
5757
return
5858
}
5959

60-
if v > max {
61-
es = append(es, fmt.Errorf("expected %s to be at most (%f), got %f", k, max, v))
60+
if v > maxVal {
61+
es = append(es, fmt.Errorf("expected %s to be at most (%f), got %f", k, maxVal, v))
6262
return
6363
}
6464

helper/validation/int.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import (
1111
)
1212

1313
// IntBetween returns a SchemaValidateFunc which tests if the provided value
14-
// is of type int and is between min and max (inclusive)
15-
func IntBetween(min, max int) schema.SchemaValidateFunc {
14+
// is of type int and is between minVal and maxVal (inclusive)
15+
func IntBetween(minVal, maxVal int) schema.SchemaValidateFunc {
1616
return func(i interface{}, k string) (warnings []string, errors []error) {
1717
v, ok := i.(int)
1818
if !ok {
1919
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
2020
return warnings, errors
2121
}
2222

23-
if v < min || v > max {
24-
errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v))
23+
if v < minVal || v > maxVal {
24+
errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, minVal, maxVal, v))
2525
return warnings, errors
2626
}
2727

@@ -30,17 +30,17 @@ func IntBetween(min, max int) schema.SchemaValidateFunc {
3030
}
3131

3232
// IntAtLeast returns a SchemaValidateFunc which tests if the provided value
33-
// is of type int and is at least min (inclusive)
34-
func IntAtLeast(min int) schema.SchemaValidateFunc {
33+
// is of type int and is at least minVal (inclusive)
34+
func IntAtLeast(minVal int) schema.SchemaValidateFunc {
3535
return func(i interface{}, k string) (warnings []string, errors []error) {
3636
v, ok := i.(int)
3737
if !ok {
3838
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
3939
return warnings, errors
4040
}
4141

42-
if v < min {
43-
errors = append(errors, fmt.Errorf("expected %s to be at least (%d), got %d", k, min, v))
42+
if v < minVal {
43+
errors = append(errors, fmt.Errorf("expected %s to be at least (%d), got %d", k, minVal, v))
4444
return warnings, errors
4545
}
4646

@@ -49,17 +49,17 @@ func IntAtLeast(min int) schema.SchemaValidateFunc {
4949
}
5050

5151
// IntAtMost returns a SchemaValidateFunc which tests if the provided value
52-
// is of type int and is at most max (inclusive)
53-
func IntAtMost(max int) schema.SchemaValidateFunc {
52+
// is of type int and is at most maxVal (inclusive)
53+
func IntAtMost(maxVal int) schema.SchemaValidateFunc {
5454
return func(i interface{}, k string) (warnings []string, errors []error) {
5555
v, ok := i.(int)
5656
if !ok {
5757
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
5858
return warnings, errors
5959
}
6060

61-
if v > max {
62-
errors = append(errors, fmt.Errorf("expected %s to be at most (%d), got %d", k, max, v))
61+
if v > maxVal {
62+
errors = append(errors, fmt.Errorf("expected %s to be at most (%d), got %d", k, maxVal, v))
6363
return warnings, errors
6464
}
6565

helper/validation/map.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ import (
99
"sort"
1010

1111
"github.com/hashicorp/go-cty/cty"
12+
1213
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1415
)
1516

1617
// MapKeyLenBetween returns a SchemaValidateDiagFunc which tests if the provided value
17-
// is of type map and the length of all keys are between min and max (inclusive)
18-
func MapKeyLenBetween(min, max int) schema.SchemaValidateDiagFunc {
18+
// is of type map and the length of all keys are between minVal and maxVal (inclusive)
19+
func MapKeyLenBetween(minVal, maxVal int) schema.SchemaValidateDiagFunc {
1920
return func(v interface{}, path cty.Path) diag.Diagnostics {
2021
var diags diag.Diagnostics
2122

2223
for _, key := range sortedKeys(v.(map[string]interface{})) {
2324
keyLen := len(key)
24-
if keyLen < min || keyLen > max {
25+
if keyLen < minVal || keyLen > maxVal {
2526
diags = append(diags, diag.Diagnostic{
2627
Severity: diag.Error,
2728
Summary: "Bad map key length",
28-
Detail: fmt.Sprintf("Map key lengths should be in the range (%d - %d): %s (length = %d)", min, max, key, keyLen),
29+
Detail: fmt.Sprintf("Map key lengths should be in the range (%d - %d): %s (length = %d)", minVal, maxVal, key, keyLen),
2930
AttributePath: append(path, cty.IndexStep{Key: cty.StringVal(key)}),
3031
})
3132
}
@@ -36,8 +37,8 @@ func MapKeyLenBetween(min, max int) schema.SchemaValidateDiagFunc {
3637
}
3738

3839
// MapValueLenBetween returns a SchemaValidateDiagFunc which tests if the provided value
39-
// is of type map and the length of all values are between min and max (inclusive)
40-
func MapValueLenBetween(min, max int) schema.SchemaValidateDiagFunc {
40+
// is of type map and the length of all values are between minVal and maxVal (inclusive)
41+
func MapValueLenBetween(minVal, maxVal int) schema.SchemaValidateDiagFunc {
4142
return func(v interface{}, path cty.Path) diag.Diagnostics {
4243
var diags diag.Diagnostics
4344

@@ -57,11 +58,11 @@ func MapValueLenBetween(min, max int) schema.SchemaValidateDiagFunc {
5758
}
5859

5960
valLen := len(val.(string))
60-
if valLen < min || valLen > max {
61+
if valLen < minVal || valLen > maxVal {
6162
diags = append(diags, diag.Diagnostic{
6263
Severity: diag.Error,
6364
Summary: "Bad map value length",
64-
Detail: fmt.Sprintf("Map value lengths should be in the range (%d - %d): %s => %v (length = %d)", min, max, key, val, valLen),
65+
Detail: fmt.Sprintf("Map value lengths should be in the range (%d - %d): %s => %v (length = %d)", minVal, maxVal, key, val, valLen),
6566
AttributePath: append(path, cty.IndexStep{Key: cty.StringVal(key)}),
6667
})
6768
}

helper/validation/network.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func IsCIDR(i interface{}, k string) (warnings []string, errors []error) {
9999
}
100100

101101
// IsCIDRNetwork returns a SchemaValidateFunc which tests if the provided value
102-
// is of type string, is in valid Value network notation, and has significant bits between min and max (inclusive)
103-
func IsCIDRNetwork(min, max int) schema.SchemaValidateFunc {
102+
// is of type string, is in valid Value network notation, and has significant bits between minVal and maxVal (inclusive)
103+
func IsCIDRNetwork(minVal, maxVal int) schema.SchemaValidateFunc {
104104
return func(i interface{}, k string) (warnings []string, errors []error) {
105105
v, ok := i.(string)
106106
if !ok {
@@ -120,8 +120,8 @@ func IsCIDRNetwork(min, max int) schema.SchemaValidateFunc {
120120
}
121121

122122
sigbits, _ := ipnet.Mask.Size()
123-
if sigbits < min || sigbits > max {
124-
errors = append(errors, fmt.Errorf("expected %q to contain a network Value with between %d and %d significant bits, got: %d", k, min, max, sigbits))
123+
if sigbits < minVal || sigbits > maxVal {
124+
errors = append(errors, fmt.Errorf("expected %q to contain a network Value with between %d and %d significant bits, got: %d", k, minVal, maxVal, sigbits))
125125
}
126126

127127
return warnings, errors

helper/validation/strings.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ func StringIsWhiteSpace(i interface{}, k string) ([]string, []error) {
7070
}
7171

7272
// StringLenBetween returns a SchemaValidateFunc which tests if the provided value
73-
// is of type string and has length between min and max (inclusive)
74-
func StringLenBetween(min, max int) schema.SchemaValidateFunc {
73+
// is of type string and has length between minVal and maxVal (inclusive)
74+
func StringLenBetween(minVal, maxVal int) schema.SchemaValidateFunc {
7575
return func(i interface{}, k string) (warnings []string, errors []error) {
7676
v, ok := i.(string)
7777
if !ok {
7878
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
7979
return warnings, errors
8080
}
8181

82-
if len(v) < min || len(v) > max {
83-
errors = append(errors, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, min, max, v))
82+
if len(v) < minVal || len(v) > maxVal {
83+
errors = append(errors, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, minVal, maxVal, v))
8484
}
8585

8686
return warnings, errors

0 commit comments

Comments
 (0)