lint: apply x/tools/modernize fixes

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2025-03-07 15:00:35 -08:00
parent e19c729d3e
commit d5d3d3d502
50 changed files with 238 additions and 266 deletions

View File

@ -16,8 +16,8 @@ import (
)
func TestDecodeBody(t *testing.T) {
deepEquals := func(other interface{}) func(v interface{}) bool {
return func(v interface{}) bool {
deepEquals := func(other any) func(v any) bool {
return func(v any) bool {
return reflect.DeepEqual(v, other)
}
}
@ -45,19 +45,19 @@ func TestDecodeBody(t *testing.T) {
}
tests := []struct {
Body map[string]interface{}
Target func() interface{}
Check func(v interface{}) bool
Body map[string]any
Target func() any
Check func(v any) bool
DiagCount int
}{
{
map[string]interface{}{},
map[string]any{},
makeInstantiateType(struct{}{}),
deepEquals(struct{}{}),
0,
},
{
map[string]interface{}{},
map[string]any{},
makeInstantiateType(struct {
Name string `hcl:"name"`
}{}),
@ -67,7 +67,7 @@ func TestDecodeBody(t *testing.T) {
1, // name is required
},
{
map[string]interface{}{},
map[string]any{},
makeInstantiateType(struct {
Name *string `hcl:"name"`
}{}),
@ -77,7 +77,7 @@ func TestDecodeBody(t *testing.T) {
0,
}, // name nil
{
map[string]interface{}{},
map[string]any{},
makeInstantiateType(struct {
Name string `hcl:"name,optional"`
}{}),
@ -87,9 +87,9 @@ func TestDecodeBody(t *testing.T) {
0,
}, // name optional
{
map[string]interface{}{},
map[string]any{},
makeInstantiateType(withNameExpression{}),
func(v interface{}) bool {
func(v any) bool {
if v == nil {
return false
}
@ -109,11 +109,11 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
},
makeInstantiateType(withNameExpression{}),
func(v interface{}) bool {
func(v any) bool {
if v == nil {
return false
}
@ -133,7 +133,7 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
},
makeInstantiateType(struct {
@ -145,7 +145,7 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 23,
},
@ -158,7 +158,7 @@ func TestDecodeBody(t *testing.T) {
1, // Extraneous "age" property
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 50,
},
@ -166,7 +166,7 @@ func TestDecodeBody(t *testing.T) {
Name string `hcl:"name"`
Attrs hcl.Attributes `hcl:",remain"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
got := gotI.(struct {
Name string `hcl:"name"`
Attrs hcl.Attributes `hcl:",remain"`
@ -176,7 +176,7 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 50,
},
@ -184,7 +184,7 @@ func TestDecodeBody(t *testing.T) {
Name string `hcl:"name"`
Remain hcl.Body `hcl:",remain"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
got := gotI.(struct {
Name string `hcl:"name"`
Remain hcl.Body `hcl:",remain"`
@ -197,7 +197,7 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"living": true,
},
@ -217,7 +217,7 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 50,
},
@ -226,7 +226,7 @@ func TestDecodeBody(t *testing.T) {
Body hcl.Body `hcl:",body"`
Remain hcl.Body `hcl:",remain"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
got := gotI.(struct {
Name string `hcl:"name"`
Body hcl.Body `hcl:",body"`
@ -241,76 +241,76 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{},
map[string]any{
"noodle": map[string]any{},
},
makeInstantiateType(struct {
Noodle struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// Generating no diagnostics is good enough for this one.
return true
},
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{{}},
map[string]any{
"noodle": []map[string]any{{}},
},
makeInstantiateType(struct {
Noodle struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// Generating no diagnostics is good enough for this one.
return true
},
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{{}, {}},
map[string]any{
"noodle": []map[string]any{{}, {}},
},
makeInstantiateType(struct {
Noodle struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// Generating one diagnostic is good enough for this one.
return true
},
1,
},
{
map[string]interface{}{},
map[string]any{},
makeInstantiateType(struct {
Noodle struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// Generating one diagnostic is good enough for this one.
return true
},
1,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{},
map[string]any{
"noodle": []map[string]any{},
},
makeInstantiateType(struct {
Noodle struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// Generating one diagnostic is good enough for this one.
return true
},
1,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{},
map[string]any{
"noodle": map[string]any{},
},
makeInstantiateType(struct {
Noodle *struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
return gotI.(struct {
Noodle *struct{} `hcl:"noodle,block"`
}).Noodle != nil
@ -318,13 +318,13 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{{}},
map[string]any{
"noodle": []map[string]any{{}},
},
makeInstantiateType(struct {
Noodle *struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
return gotI.(struct {
Noodle *struct{} `hcl:"noodle,block"`
}).Noodle != nil
@ -332,13 +332,13 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{},
map[string]any{
"noodle": []map[string]any{},
},
makeInstantiateType(struct {
Noodle *struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
return gotI.(struct {
Noodle *struct{} `hcl:"noodle,block"`
}).Noodle == nil
@ -346,26 +346,26 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{{}, {}},
map[string]any{
"noodle": []map[string]any{{}, {}},
},
makeInstantiateType(struct {
Noodle *struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// Generating one diagnostic is good enough for this one.
return true
},
1,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{},
map[string]any{
"noodle": []map[string]any{},
},
makeInstantiateType(struct {
Noodle []struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
noodle := gotI.(struct {
Noodle []struct{} `hcl:"noodle,block"`
}).Noodle
@ -374,13 +374,13 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{{}},
map[string]any{
"noodle": []map[string]any{{}},
},
makeInstantiateType(struct {
Noodle []struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
noodle := gotI.(struct {
Noodle []struct{} `hcl:"noodle,block"`
}).Noodle
@ -389,13 +389,13 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": []map[string]interface{}{{}, {}},
map[string]any{
"noodle": []map[string]any{{}, {}},
},
makeInstantiateType(struct {
Noodle []struct{} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
noodle := gotI.(struct {
Noodle []struct{} `hcl:"noodle,block"`
}).Noodle
@ -404,15 +404,15 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{},
map[string]any{
"noodle": map[string]any{},
},
makeInstantiateType(struct {
Noodle struct {
Name string `hcl:"name,label"`
} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
//nolint:misspell
// Generating two diagnostics is good enough for this one.
// (one for the missing noodle block and the other for
@ -423,9 +423,9 @@ func TestDecodeBody(t *testing.T) {
2,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{
"foo_foo": map[string]interface{}{},
map[string]any{
"noodle": map[string]any{
"foo_foo": map[string]any{},
},
},
makeInstantiateType(struct {
@ -433,7 +433,7 @@ func TestDecodeBody(t *testing.T) {
Name string `hcl:"name,label"`
} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
noodle := gotI.(struct {
Noodle struct {
Name string `hcl:"name,label"`
@ -444,10 +444,10 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{
"foo_foo": map[string]interface{}{},
"bar_baz": map[string]interface{}{},
map[string]any{
"noodle": map[string]any{
"foo_foo": map[string]any{},
"bar_baz": map[string]any{},
},
},
makeInstantiateType(struct {
@ -455,17 +455,17 @@ func TestDecodeBody(t *testing.T) {
Name string `hcl:"name,label"`
} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
// One diagnostic is enough for this one.
return true
},
1,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{
"foo_foo": map[string]interface{}{},
"bar_baz": map[string]interface{}{},
map[string]any{
"noodle": map[string]any{
"foo_foo": map[string]any{},
"bar_baz": map[string]any{},
},
},
makeInstantiateType(struct {
@ -473,7 +473,7 @@ func TestDecodeBody(t *testing.T) {
Name string `hcl:"name,label"`
} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
noodles := gotI.(struct {
Noodles []struct {
Name string `hcl:"name,label"`
@ -484,9 +484,9 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
"noodle": map[string]interface{}{
"foo_foo": map[string]interface{}{
map[string]any{
"noodle": map[string]any{
"foo_foo": map[string]any{
"type": "rice",
},
},
@ -497,7 +497,7 @@ func TestDecodeBody(t *testing.T) {
Type string `hcl:"type"`
} `hcl:"noodle,block"`
}{}),
func(gotI interface{}) bool {
func(gotI any) bool {
noodle := gotI.(struct {
Noodle struct {
Name string `hcl:"name,label"`
@ -510,7 +510,7 @@ func TestDecodeBody(t *testing.T) {
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 34,
},
@ -522,31 +522,31 @@ func TestDecodeBody(t *testing.T) {
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 89,
},
makeInstantiateType(map[string]*hcl.Attribute(nil)),
func(gotI interface{}) bool {
func(gotI any) bool {
got := gotI.(map[string]*hcl.Attribute)
return len(got) == 2 && got["name"] != nil && got["age"] != nil
},
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"age": 13,
},
makeInstantiateType(map[string]hcl.Expression(nil)),
func(gotI interface{}) bool {
func(gotI any) bool {
got := gotI.(map[string]hcl.Expression)
return len(got) == 2 && got["name"] != nil && got["age"] != nil
},
0,
},
{
map[string]interface{}{
map[string]any{
"name": "Ermintrude",
"living": true,
},
@ -559,10 +559,10 @@ func TestDecodeBody(t *testing.T) {
},
{
// Retain "nested" block while decoding
map[string]interface{}{
map[string]any{
"plain": "foo",
},
func() interface{} {
func() any {
return &withNestedBlock{
Plain: "bar",
Nested: &withTwoAttributes{
@ -570,7 +570,7 @@ func TestDecodeBody(t *testing.T) {
},
}
},
func(gotI interface{}) bool {
func(gotI any) bool {
foo := gotI.(withNestedBlock)
return foo.Plain == "foo" && foo.Nested != nil && foo.Nested.A == "bar"
},
@ -578,19 +578,19 @@ func TestDecodeBody(t *testing.T) {
},
{
// Retain values in "nested" block while decoding
map[string]interface{}{
"nested": map[string]interface{}{
map[string]any{
"nested": map[string]any{
"a": "foo",
},
},
func() interface{} {
func() any {
return &withNestedBlock{
Nested: &withTwoAttributes{
B: "bar",
},
}
},
func(gotI interface{}) bool {
func(gotI any) bool {
foo := gotI.(withNestedBlock)
return foo.Nested.A == "foo" && foo.Nested.B == "bar"
},
@ -598,14 +598,14 @@ func TestDecodeBody(t *testing.T) {
},
{
// Retain values in "nested" block list while decoding
map[string]interface{}{
"nested": []map[string]interface{}{
map[string]any{
"nested": []map[string]any{
{
"a": "foo",
},
},
},
func() interface{} {
func() any {
return &withListofNestedBlocks{
Nested: []*withTwoAttributes{
{
@ -614,7 +614,7 @@ func TestDecodeBody(t *testing.T) {
},
}
},
func(gotI interface{}) bool {
func(gotI any) bool {
n := gotI.(withListofNestedBlocks)
return n.Nested[0].A == "foo" && n.Nested[0].B == "bar"
},
@ -622,14 +622,14 @@ func TestDecodeBody(t *testing.T) {
},
{
// Remove additional elements from the list while decoding nested blocks
map[string]interface{}{
"nested": []map[string]interface{}{
map[string]any{
"nested": []map[string]any{
{
"a": "foo",
},
},
},
func() interface{} {
func() any {
return &withListofNestedBlocks{
Nested: []*withTwoAttributes{
{
@ -641,7 +641,7 @@ func TestDecodeBody(t *testing.T) {
},
}
},
func(gotI interface{}) bool {
func(gotI any) bool {
n := gotI.(withListofNestedBlocks)
return len(n.Nested) == 1
},
@ -649,8 +649,8 @@ func TestDecodeBody(t *testing.T) {
},
{
// Make sure decoding value slices works the same as pointer slices.
map[string]interface{}{
"nested": []map[string]interface{}{
map[string]any{
"nested": []map[string]any{
{
"b": "bar",
},
@ -659,7 +659,7 @@ func TestDecodeBody(t *testing.T) {
},
},
},
func() interface{} {
func() any {
return &withListofNestedBlocksNoPointers{
Nested: []withTwoAttributes{
{
@ -668,7 +668,7 @@ func TestDecodeBody(t *testing.T) {
},
}
},
func(gotI interface{}) bool {
func(gotI any) bool {
n := gotI.(withListofNestedBlocksNoPointers)
return n.Nested[0].B == "bar" && len(n.Nested) == 2
},
@ -710,8 +710,8 @@ func TestDecodeBody(t *testing.T) {
func TestDecodeExpression(t *testing.T) {
tests := []struct {
Value cty.Value
Target interface{}
Want interface{}
Target any
Want any
DiagCount int
}{
{
@ -799,8 +799,8 @@ func (e *fixedExpression) Variables() []hcl.Traversal {
return nil
}
func makeInstantiateType(target interface{}) func() interface{} {
return func() interface{} {
func makeInstantiateType(target any) func() any {
return func() any {
return reflect.New(reflect.TypeOf(target)).Interface()
}
}