Skip to content

Commit 5434c90

Browse files
alexandearfredbi
authored andcommitted
lint: fix modernize issues
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent ca4d1dd commit 5434c90

File tree

11 files changed

+24
-29
lines changed

11 files changed

+24
-29
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ linters:
2121
- ireturn
2222
- lll
2323
- musttag
24+
- modernize
2425
- nestif
2526
- nlreturn
2627
- nonamedreturns

cmdutils/cmd_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ package cmdutils
99
type CommandLineOptionsGroup struct {
1010
ShortDescription string
1111
LongDescription string
12-
Options interface{}
12+
Options any
1313
}

conv/convert_types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func assertSingleValue(t *testing.T, inElem, elem reflect.Value, expectPointer b
162162
}
163163

164164
// assertValues checks equivalent representation pointer vs values for single var, slices and maps
165-
func assertValues(t *testing.T, in, out interface{}, expectPointer bool, idx int) {
165+
func assertValues(t *testing.T, in, out any, expectPointer bool, idx int) {
166166
vin := reflect.ValueOf(in)
167167
vout := reflect.ValueOf(out)
168168

fileutils/file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
)
1212

1313
func TestFileImplementsIOReader(t *testing.T) {
14-
var file interface{} = &File{}
14+
var file any = &File{}
1515
expected := "that File implements io.Reader"
1616
assert.Implements(t, new(io.Reader), file, expected)
1717
}
1818

1919
func TestFileImplementsIOReadCloser(t *testing.T) {
20-
var file interface{} = &File{}
20+
var file any = &File{}
2121
expected := "that File implements io.ReadCloser"
2222
assert.Implements(t, new(io.ReadCloser), file, expected)
2323
}

jsonname/name_provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func newNameIndex(tpe reflect.Type) nameIndex {
7979
}
8080

8181
// GetJSONNames gets all the json property names for a type
82-
func (n *NameProvider) GetJSONNames(subject interface{}) []string {
82+
func (n *NameProvider) GetJSONNames(subject any) []string {
8383
n.lock.Lock()
8484
defer n.lock.Unlock()
8585
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
@@ -96,7 +96,7 @@ func (n *NameProvider) GetJSONNames(subject interface{}) []string {
9696
}
9797

9898
// GetJSONName gets the json name for a go property name
99-
func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool) {
99+
func (n *NameProvider) GetJSONName(subject any, name string) (string, bool) {
100100
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
101101
return n.GetJSONNameForType(tpe, name)
102102
}
@@ -114,7 +114,7 @@ func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string
114114
}
115115

116116
// GetGoName gets the go name for a json property name
117-
func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool) {
117+
func (n *NameProvider) GetGoName(subject any, name string) (string, bool) {
118118
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
119119
return n.GetGoNameForType(tpe, name)
120120
}

jsonutils_iface.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ type JSONMapItem = jsonutils.JSONMapItem
2222
// WriteJSON writes json data.
2323
//
2424
// Deprecated: use [jsonutils.WriteJSON] instead.
25-
func WriteJSON(data interface{}) ([]byte, error) { return jsonutils.WriteJSON(data) }
25+
func WriteJSON(data any) ([]byte, error) { return jsonutils.WriteJSON(data) }
2626

2727
// ReadJSON reads json data.
2828
//
2929
// Deprecated: use [jsonutils.ReadJSON] instead.
30-
func ReadJSON(data []byte, value interface{}) error { return jsonutils.ReadJSON(data, value) }
30+
func ReadJSON(data []byte, value any) error { return jsonutils.ReadJSON(data, value) }
3131

3232
// DynamicJSONToStruct converts an untyped JSON structure into a target data type.
3333
//
3434
// Deprecated: use [jsonutils.FromDynamicJSON] instead.
35-
func DynamicJSONToStruct(data interface{}, target interface{}) error {
35+
func DynamicJSONToStruct(data any, target any) error {
3636
return jsonutils.FromDynamicJSON(data, target)
3737
}
3838

@@ -46,8 +46,8 @@ func ConcatJSON(blobs ...[]byte) []byte { return jsonutils.ConcatJSON(blobs...)
4646
// It is the same as [FromDynamicJSON], but doesn't check for errors.
4747
//
4848
// Deprecated: this function is a misnomer and is unsafe. Use [jsonutils.FromDynamicJSON] instead.
49-
func ToDynamicJSON(value interface{}) interface{} {
50-
var res interface{}
49+
func ToDynamicJSON(value any) any {
50+
var res any
5151
if err := FromDynamicJSON(value, &res); err != nil {
5252
log.Println(err)
5353
}
@@ -57,9 +57,9 @@ func ToDynamicJSON(value interface{}) interface{} {
5757

5858
// FromDynamicJSON turns a go value into a properly JSON typed structure.
5959
//
60-
// "Dynamic JSON" refers to what you get when unmarshaling JSON into an untyped interface{},
61-
// i.e. objects are represented by map[string]interface{}, arrays by []interface{}, and all
62-
// scalar values are interface{}.
60+
// "Dynamic JSON" refers to what you get when unmarshaling JSON into an untyped any,
61+
// i.e. objects are represented by map[string]any, arrays by []any, and all
62+
// scalar values are any.
6363
//
6464
// Deprecated: use [jsonutils.FromDynamicJSON] instead.
65-
func FromDynamicJSON(data, target interface{}) error { return jsonutils.FromDynamicJSON(data, target) }
65+
func FromDynamicJSON(data, target any) error { return jsonutils.FromDynamicJSON(data, target) }

loading/yaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func YAMLDoc(path string, opts ...Option) (json.RawMessage, error) {
2727
}
2828

2929
// YAMLData loads a yaml document from either http or a file.
30-
func YAMLData(path string, opts ...Option) (interface{}, error) {
30+
func YAMLData(path string, opts ...Option) (any, error) {
3131
data, err := LoadFromFileOrHTTP(path, opts...)
3232
if err != nil {
3333
return nil, err

loading_iface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func YAMLDoc(path string) (json.RawMessage, error) {
7373
// YAMLData loads a yaml document from either http or a file.
7474
//
7575
// Deprecated: use [loading.YAMLData] instead.
76-
func YAMLData(path string) (interface{}, error) {
76+
func YAMLData(path string) (any, error) {
7777
return loading.YAMLData(path)
7878
}
7979

loading_iface_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"net/http"
99
"net/http/httptest"
10+
"slices"
1011
"testing"
1112
"time"
1213

@@ -62,14 +63,7 @@ func TestLoadFromHTTP(t *testing.T) {
6263

6364
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
6465
myHeaders := r.Header[sharedHeaderKey]
65-
ok := false
66-
for _, v := range myHeaders {
67-
if v == sharedHeaderValue {
68-
ok = true
69-
break
70-
}
71-
}
72-
if ok {
66+
if slices.Contains(myHeaders, sharedHeaderValue) {
7367
rw.WriteHeader(http.StatusOK)
7468
} else {
7569
rw.WriteHeader(http.StatusForbidden)

typeutils_iface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import "github.com/go-openapi/swag/typeutils"
99
// This allows for safer checking of interface values.
1010
//
1111
// Deprecated: use [typeutils.IsZero] instead.
12-
func IsZero(data interface{}) bool { return typeutils.IsZero(data) }
12+
func IsZero(data any) bool { return typeutils.IsZero(data) }

0 commit comments

Comments
 (0)