Skip to content

Commit 7a0606c

Browse files
lint fixes (#146)
1 parent a54af38 commit 7a0606c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+596
-590
lines changed

ascii/ascii_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func BenchmarkValidPrint(b *testing.B) {
9797
func benchmarkValidationFunction(b *testing.B, function func(string) bool) {
9898
for _, test := range testStrings {
9999
b.Run(limit(test), func(b *testing.B) {
100-
for i := 0; i < b.N; i++ {
100+
for range b.N {
101101
_ = function(test)
102102
}
103103
b.SetBytes(int64(len(test)))
@@ -233,7 +233,7 @@ func BenchmarkEqualFold(b *testing.B) {
233233
b.Run(limit(test), func(b *testing.B) {
234234
other := test + "_" // not the same pointer
235235

236-
for i := 0; i < b.N; i++ {
236+
for range b.N {
237237
_ = EqualFoldString(test, other[:len(test)]) // same length
238238
}
239239

internal/runtime_reflect/map.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func makemap(t unsafe.Pointer, cap int) unsafe.Pointer
7979

8080
// m escapes into the return value, but the caller of mapiterinit
8181
// doesn't let the return value escape.
82+
//
8283
//go:noescape
8384
//go:linkname mapiterinit runtime.mapiterinit
8485
func mapiterinit(t unsafe.Pointer, m unsafe.Pointer, it *hiter)

iso8601/parse_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func TestParse(t *testing.T) {
7878
}
7979

8080
// Check ~4M YYYY-MM-DD dates in 20 byte form.
81-
for year := 0; year <= 9999; year++ {
82-
for month := 0; month <= 13; month++ {
83-
for day := 0; day <= 32; day++ {
81+
for year := range 10000 {
82+
for month := range 14 {
83+
for day := range 33 {
8484
input := fmt.Sprintf("%04d-%02d-%02dT12:34:56Z", year, month, day)
8585
expect, expectErr := time.Parse(time.RFC3339Nano, input)
8686
actual, actualErr := Parse(input)
@@ -94,9 +94,9 @@ func TestParse(t *testing.T) {
9494
}
9595

9696
// Check ~4M YYYY-MM-DD dates in 24 byte form.
97-
for year := 0; year <= 9999; year++ {
98-
for month := 0; month <= 13; month++ {
99-
for day := 0; day <= 32; day++ {
97+
for year := range 10000 {
98+
for month := range 14 {
99+
for day := range 33 {
100100
input := fmt.Sprintf("%04d-%02d-%02dT12:34:56.789Z", year, month, day)
101101
expect, expectErr := time.Parse(time.RFC3339Nano, input)
102102
actual, actualErr := Parse(input)
@@ -110,9 +110,9 @@ func TestParse(t *testing.T) {
110110
}
111111

112112
// Check ~4M YYYY-MM-DD dates in 30 byte form.
113-
for year := 0; year <= 9999; year++ {
114-
for month := 0; month <= 13; month++ {
115-
for day := 0; day <= 32; day++ {
113+
for year := range 10000 {
114+
for month := range 14 {
115+
for day := range 33 {
116116
input := fmt.Sprintf("%04d-%02d-%02dT12:34:56.123456789Z", year, month, day)
117117
expect, expectErr := time.Parse(time.RFC3339Nano, input)
118118
actual, actualErr := Parse(input)
@@ -126,9 +126,9 @@ func TestParse(t *testing.T) {
126126
}
127127

128128
// Check all ~1M HH:MM:SS times in 20 byte form.
129-
for hour := 0; hour < 100; hour++ {
130-
for minute := 0; minute < 100; minute++ {
131-
for second := 0; second < 100; second++ {
129+
for hour := range 100 {
130+
for minute := range 100 {
131+
for second := range 100 {
132132
input := fmt.Sprintf("2000-01-01T%02d:%02d:%02dZ", hour, minute, second)
133133
expect, expectErr := time.Parse(time.RFC3339Nano, input)
134134
actual, actualErr := Parse(input)
@@ -142,9 +142,9 @@ func TestParse(t *testing.T) {
142142
}
143143

144144
// Check ~1M HH:MM:SS.MMM times in 24 byte form.
145-
for hour := 0; hour < 100; hour++ {
146-
for minute := 0; minute < 100; minute++ {
147-
for second := 0; second < 100; second++ {
145+
for hour := range 100 {
146+
for minute := range 100 {
147+
for second := range 100 {
148148
input := fmt.Sprintf("2000-01-01T%02d:%02d:%02d.123Z", hour, minute, second)
149149
expect, expectErr := time.Parse(time.RFC3339Nano, input)
150150
actual, actualErr := Parse(input)
@@ -158,9 +158,9 @@ func TestParse(t *testing.T) {
158158
}
159159

160160
// Check ~1M HH:MM:SS.MMM times in 30 byte form.
161-
for hour := 0; hour < 100; hour++ {
162-
for minute := 0; minute < 100; minute++ {
163-
for second := 0; second < 100; second++ {
161+
for hour := range 100 {
162+
for minute := range 100 {
163+
for second := range 100 {
164164
input := fmt.Sprintf("2000-01-01T%02d:%02d:%02d.123456789Z", hour, minute, second)
165165
expect, expectErr := time.Parse(time.RFC3339Nano, input)
166166
actual, actualErr := Parse(input)
@@ -405,31 +405,31 @@ func TestParseInvalid(t *testing.T) {
405405
}
406406

407407
func BenchmarkParse(b *testing.B) {
408-
for i := 0; i < b.N; i++ {
408+
for range b.N {
409409
Parse("2006-01-02T15:04:05Z")
410410
}
411411
}
412412

413413
func BenchmarkParseMilliseconds(b *testing.B) {
414-
for i := 0; i < b.N; i++ {
414+
for range b.N {
415415
Parse("2006-01-02T15:04:05.123Z")
416416
}
417417
}
418418

419419
func BenchmarkParseMicroseconds(b *testing.B) {
420-
for i := 0; i < b.N; i++ {
420+
for range b.N {
421421
Parse("2006-01-02T15:04:05.123456Z")
422422
}
423423
}
424424

425425
func BenchmarkParseNanoseconds(b *testing.B) {
426-
for i := 0; i < b.N; i++ {
426+
for range b.N {
427427
Parse("2006-01-02T15:04:05.123456789Z")
428428
}
429429
}
430430

431431
func BenchmarkParseInvalid(b *testing.B) {
432-
for i := 0; i < b.N; i++ {
432+
for range b.N {
433433
Parse("2006-01-02T15:04:05.XZ")
434434
}
435435
}

iso8601/valid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package iso8601
22

33
// ValidFlags is a bitset type used to configure the behavior of the Valid
4-
//function.
4+
// function.
55
type ValidFlags int
66

77
const (

iso8601/valid_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ func BenchmarkValidate(b *testing.B) {
6868
}
6969

7070
func benchmarkValidateSuccess(b *testing.B) {
71-
for i := 0; i < b.N; i++ {
71+
for range b.N {
7272
if !Valid("2018-01-01T23:42:59.123456789Z", Flexible) {
7373
b.Fatal("not valid")
7474
}
7575
}
7676
}
7777

7878
func benchmarkValidateFailure(b *testing.B) {
79-
for i := 0; i < b.N; i++ {
79+
for range b.N {
8080
if Valid("2018-01-01T23:42:59 oops!", Flexible) {
8181
b.Fatal("valid but should not")
8282
}
@@ -89,15 +89,15 @@ func BenchmarkTimeParse(b *testing.B) {
8989
}
9090

9191
func benchmarkTimeParseSuccess(b *testing.B) {
92-
for i := 0; i < b.N; i++ {
92+
for range b.N {
9393
if _, err := time.Parse(time.RFC3339Nano, "2018-01-01T23:42:59.123456789Z"); err != nil {
9494
b.Fatal("not valid")
9595
}
9696
}
9797
}
9898

9999
func benchmarkTimeParseFailure(b *testing.B) {
100-
for i := 0; i < b.N; i++ {
100+
for range b.N {
101101
if _, err := time.Parse(time.RFC3339Nano, "2018-01-01T23:42:59 oops!"); err == nil {
102102
b.Fatal("valid but should not")
103103
}

json/bugs/issue11/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestIssue11(t *testing.T) {
12-
m := map[string]map[string]interface{}{
12+
m := map[string]map[string]any{
1313
"outerkey": {
1414
"innerkey": "innervalue",
1515
},

json/codec.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ type decoder struct {
4444
flags ParseFlags
4545
}
4646

47-
type encodeFunc func(encoder, []byte, unsafe.Pointer) ([]byte, error)
48-
type decodeFunc func(decoder, []byte, unsafe.Pointer) ([]byte, error)
47+
type (
48+
encodeFunc func(encoder, []byte, unsafe.Pointer) ([]byte, error)
49+
decodeFunc func(decoder, []byte, unsafe.Pointer) ([]byte, error)
50+
)
4951

50-
type emptyFunc func(unsafe.Pointer) bool
51-
type sortFunc func([]reflect.Value)
52+
type (
53+
emptyFunc func(unsafe.Pointer) bool
54+
sortFunc func([]reflect.Value)
55+
)
5256

5357
// Eventually consistent cache mapping go types to dynamically generated
5458
// codecs.
@@ -558,7 +562,7 @@ func appendStructFields(fields []structField, t reflect.Type, offset uintptr, se
558562
names := make(map[string]struct{})
559563
embedded := make([]embeddedField, 0, 10)
560564

561-
for i, n := 0, t.NumField(); i < n; i++ {
565+
for i := range t.NumField() {
562566
f := t.Field(i)
563567

564568
var (
@@ -706,7 +710,7 @@ func appendStructFields(fields []structField, t reflect.Type, offset uintptr, se
706710
for _, embfield := range embedded {
707711
subfield := *embfield.subfield
708712

709-
if ambiguousNames[subfield.name] > 1 && !(subfield.tag && ambiguousTags[subfield.name] == 1) {
713+
if ambiguousNames[subfield.name] > 1 && (!subfield.tag || ambiguousTags[subfield.name] != 1) {
710714
continue // ambiguous embedded field
711715
}
712716

@@ -1001,14 +1005,14 @@ var syntaxErrorMsgOffset = ^uintptr(0)
10011005

10021006
func init() {
10031007
t := reflect.TypeOf(SyntaxError{})
1004-
for i, n := 0, t.NumField(); i < n; i++ {
1008+
for i := range t.NumField() {
10051009
if f := t.Field(i); f.Type.Kind() == reflect.String {
10061010
syntaxErrorMsgOffset = f.Offset
10071011
}
10081012
}
10091013
}
10101014

1011-
func syntaxError(b []byte, msg string, args ...interface{}) error {
1015+
func syntaxError(b []byte, msg string, args ...any) error {
10121016
e := new(SyntaxError)
10131017
i := syntaxErrorMsgOffset
10141018
if i != ^uintptr(0) {
@@ -1096,15 +1100,15 @@ var (
10961100
timePtrType = reflect.PtrTo(timeType)
10971101
rawMessagePtrType = reflect.PtrTo(rawMessageType)
10981102

1099-
sliceInterfaceType = reflect.TypeOf(([]interface{})(nil))
1100-
sliceStringType = reflect.TypeOf(([]interface{})(nil))
1101-
mapStringInterfaceType = reflect.TypeOf((map[string]interface{})(nil))
1103+
sliceInterfaceType = reflect.TypeOf(([]any)(nil))
1104+
sliceStringType = reflect.TypeOf(([]any)(nil))
1105+
mapStringInterfaceType = reflect.TypeOf((map[string]any)(nil))
11021106
mapStringRawMessageType = reflect.TypeOf((map[string]RawMessage)(nil))
11031107
mapStringStringType = reflect.TypeOf((map[string]string)(nil))
11041108
mapStringStringSliceType = reflect.TypeOf((map[string][]string)(nil))
11051109
mapStringBoolType = reflect.TypeOf((map[string]bool)(nil))
11061110

1107-
interfaceType = reflect.TypeOf((*interface{})(nil)).Elem()
1111+
interfaceType = reflect.TypeOf((*any)(nil)).Elem()
11081112
jsonMarshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
11091113
jsonUnmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
11101114
textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
@@ -1203,7 +1207,7 @@ func fmtFrac(buf []byte, v uint64, prec int) (nw int, nv uint64) {
12031207
// Omit trailing zeros up to and including decimal point.
12041208
w := len(buf)
12051209
print := false
1206-
for i := 0; i < prec; i++ {
1210+
for range prec {
12071211
digit := v % 10
12081212
print = print || digit != 0
12091213
if print {

0 commit comments

Comments
 (0)