Skip to content

Commit 25d4e0a

Browse files
committed
chore(lint): update linter config, relinted code
Signed-off-by: Frédéric BIDON <[email protected]>
1 parent 430601d commit 25d4e0a

File tree

8 files changed

+57
-43
lines changed

8 files changed

+57
-43
lines changed

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ linters:
1616
- godox
1717
- gosmopolitan
1818
- inamedparam
19+
- intrange # disabled while < go1.22
1920
- ireturn
2021
- lll
2122
- musttag
2223
- nestif
2324
- nlreturn
2425
- nonamedreturns
26+
- noinlineerr
2527
- paralleltest
28+
- recvcheck
2629
- testpackage
2730
- thelper
2831
- tparallel
@@ -31,6 +34,7 @@ linters:
3134
- whitespace
3235
- wrapcheck
3336
- wsl
37+
- wsl_v5
3438
settings:
3539
dupl:
3640
threshold: 200
@@ -60,3 +64,12 @@ formatters:
6064
- third_party$
6165
- builtin$
6266
- examples$
67+
issues:
68+
# Maximum issues count per one linter.
69+
# Set to 0 to disable.
70+
# Default: 50
71+
max-issues-per-linter: 0
72+
# Maximum count of issues with the same text.
73+
# Set to 0 to disable.
74+
# Default: 3
75+
max-same-issues: 0

bson.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func IsBSONObjectID(str string) bool {
3939
// ObjectId represents a BSON object ID (alias to go.mongodb.org/mongo-driver/bson/primitive.ObjectID)
4040
//
4141
// swagger:strfmt bsonobjectid
42-
type ObjectId bsonprim.ObjectID //nolint:revive,stylecheck
42+
type ObjectId bsonprim.ObjectID //nolint:revive
4343

4444
// NewObjectId creates a ObjectId from a Hex String
45-
func NewObjectId(hex string) ObjectId { //nolint:revive,stylecheck
45+
func NewObjectId(hex string) ObjectId { //nolint:revive
4646
oid, err := bsonprim.ObjectIDFromHex(hex)
4747
if err != nil {
4848
panic(err)

date_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestDate(t *testing.T) {
4848

4949
err = pp.UnmarshalJSON(bj)
5050
require.NoError(t, err)
51-
assert.EqualValues(t, orig, pp.String())
51+
assert.Equal(t, orig, pp.String())
5252

5353
err = pp.UnmarshalJSON([]byte(`"1972/01/01"`))
5454
require.Error(t, err)

default_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestFormatUUID3(t *testing.T) {
265265
var uuidZero UUID3
266266
err := uuidZero.UnmarshalJSON([]byte(jsonNull))
267267
require.NoError(t, err)
268-
assert.EqualValues(t, UUID3(""), uuidZero)
268+
assert.Equal(t, UUID3(""), uuidZero)
269269
}
270270

271271
func TestFormatUUID4(t *testing.T) {
@@ -296,7 +296,7 @@ func TestFormatUUID4(t *testing.T) {
296296
var uuidZero UUID4
297297
err := uuidZero.UnmarshalJSON([]byte(jsonNull))
298298
require.NoError(t, err)
299-
assert.EqualValues(t, UUID4(""), uuidZero)
299+
assert.Equal(t, UUID4(""), uuidZero)
300300
}
301301

302302
func TestFormatUUID5(t *testing.T) {
@@ -327,7 +327,7 @@ func TestFormatUUID5(t *testing.T) {
327327
var uuidZero UUID5
328328
err := uuidZero.UnmarshalJSON([]byte(jsonNull))
329329
require.NoError(t, err)
330-
assert.EqualValues(t, UUID5(""), uuidZero)
330+
assert.Equal(t, UUID5(""), uuidZero)
331331
}
332332

333333
func TestFormatUUID(t *testing.T) {
@@ -365,7 +365,7 @@ func TestFormatUUID(t *testing.T) {
365365
var uuidZero UUID
366366
err := uuidZero.UnmarshalJSON([]byte(jsonNull))
367367
require.NoError(t, err)
368-
assert.EqualValues(t, UUID(""), uuidZero)
368+
assert.Equal(t, UUID(""), uuidZero)
369369
}
370370

371371
func TestFormatISBN(t *testing.T) {
@@ -425,7 +425,7 @@ func TestFormatBase64(t *testing.T) {
425425
var subj Base64
426426
err := subj.UnmarshalText([]byte(str))
427427
require.NoError(t, err)
428-
assert.EqualValues(t, expected, subj)
428+
assert.Equal(t, expected, subj)
429429

430430
b, err = subj.MarshalText()
431431
require.NoError(t, err)
@@ -434,7 +434,7 @@ func TestFormatBase64(t *testing.T) {
434434
var subj2 Base64
435435
err = subj2.UnmarshalJSON(bj)
436436
require.NoError(t, err)
437-
assert.EqualValues(t, expected, subj2)
437+
assert.Equal(t, expected, subj2)
438438

439439
b, err = subj2.MarshalJSON()
440440
require.NoError(t, err)
@@ -456,18 +456,18 @@ func TestFormatBase64(t *testing.T) {
456456
require.NoError(t, err)
457457
sqlvalueAsString, ok := sqlvalue.(string)
458458
if assert.Truef(t, ok, "[%s]Value: expected driver value to be a string", "byte") {
459-
assert.EqualValuesf(t, str, sqlvalueAsString, "[%s]Value: expected %v and %v to be equal", "byte", sqlvalue, str)
459+
assert.Equal(t, str, sqlvalueAsString, "[%s]Value: expected %v and %v to be equal", "byte", sqlvalue, str)
460460
}
461461
// Scanner interface
462462
var subj3 Base64
463463
err = subj3.Scan([]byte(str))
464464
require.NoError(t, err)
465-
assert.EqualValues(t, str, subj3.String())
465+
assert.Equal(t, str, subj3.String())
466466

467467
var subj4 Base64
468468
err = subj4.Scan(str)
469469
require.NoError(t, err)
470-
assert.EqualValues(t, str, subj4.String())
470+
assert.Equal(t, str, subj4.String())
471471

472472
err = subj4.Scan(123)
473473
require.Error(t, err)
@@ -511,7 +511,7 @@ func testStringFormat(t *testing.T, what testableFormat, format, with string, va
511511
require.NoError(t, err)
512512
val = reflect.Indirect(reflect.ValueOf(what))
513513
strVal = val.String()
514-
assert.EqualValuesf(t, with, strVal, "[%s]UnmarshalJSON: expected %v and %v to be value equal", format, strVal, with)
514+
assert.Equal(t, with, strVal, "[%s]UnmarshalJSON: expected %v and %v to be value equal", format, strVal, with)
515515

516516
b, err = what.MarshalJSON()
517517
require.NoError(t, err)
@@ -527,21 +527,21 @@ func testStringFormat(t *testing.T, what testableFormat, format, with string, va
527527
require.NoError(t, err)
528528
val = reflect.Indirect(reflect.ValueOf(what))
529529
strVal = val.String()
530-
assert.EqualValuesf(t, with, strVal, "[%s]bson.Unmarshal: expected %v and %v to be equal (reset value) ", format, what, with)
530+
assert.Equal(t, with, strVal, "[%s]bson.Unmarshal: expected %v and %v to be equal (reset value) ", format, what, with)
531531

532532
// Scanner interface
533533
resetValue(t, format, what)
534534
err = what.Scan(with)
535535
require.NoError(t, err)
536536
val = reflect.Indirect(reflect.ValueOf(what))
537537
strVal = val.String()
538-
assert.EqualValuesf(t, with, strVal, "[%s]Scan: expected %v and %v to be value equal", format, strVal, with)
538+
assert.Equal(t, with, strVal, "[%s]Scan: expected %v and %v to be value equal", format, strVal, with)
539539

540540
err = what.Scan([]byte(with))
541541
require.NoError(t, err)
542542
val = reflect.Indirect(reflect.ValueOf(what))
543543
strVal = val.String()
544-
assert.EqualValuesf(t, with, strVal, "[%s]Scan: expected %v and %v to be value equal", format, strVal, with)
544+
assert.Equal(t, with, strVal, "[%s]Scan: expected %v and %v to be value equal", format, strVal, with)
545545

546546
err = what.Scan(123)
547547
require.Error(t, err)
@@ -551,7 +551,7 @@ func testStringFormat(t *testing.T, what testableFormat, format, with string, va
551551
require.NoError(t, err)
552552
sqlvalueAsString, ok := sqlvalue.(string)
553553
if assert.Truef(t, ok, "[%s]Value: expected driver value to be a string", format) {
554-
assert.EqualValuesf(t, with, sqlvalueAsString, "[%s]Value: expected %v and %v to be equal", format, sqlvalue, with)
554+
assert.Equal(t, with, sqlvalueAsString, "[%s]Value: expected %v and %v to be equal", format, sqlvalue, with)
555555
}
556556

557557
// validation with Registry

duration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestDuration(t *testing.T) {
5050

5151
err = pp.UnmarshalJSON(bj)
5252
require.NoError(t, err)
53-
assert.EqualValues(t, orig, pp.String())
53+
assert.Equal(t, orig, pp.String())
5454

5555
err = pp.UnmarshalJSON([]byte("yada"))
5656
require.Error(t, err)

format.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,29 @@ type Registry interface {
4949
GetType(string) (reflect.Type, bool)
5050
ContainsName(string) bool
5151
Validates(string, string) bool
52-
Parse(string, string) (interface{}, error)
52+
Parse(string, string) (any, error)
5353
MapStructureHookFunc() mapstructure.DecodeHookFunc
5454
}
5555

56+
// NewFormats creates a new formats registry seeded with the values from the default
57+
func NewFormats() Registry {
58+
//nolint:forcetypeassert
59+
return NewSeededFormats(Default.(*defaultFormats).data, nil)
60+
}
61+
62+
// NewSeededFormats creates a new formats registry
63+
func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
64+
if normalizer == nil {
65+
normalizer = DefaultNameNormalizer
66+
}
67+
// copy here, don't modify original
68+
d := append([]knownFormat(nil), seeds...)
69+
return &defaultFormats{
70+
data: d,
71+
normalizeName: normalizer,
72+
}
73+
}
74+
5675
type knownFormat struct {
5776
Name string
5877
OrigName string
@@ -70,32 +89,14 @@ func DefaultNameNormalizer(name string) string {
7089

7190
type defaultFormats struct {
7291
sync.Mutex
92+
7393
data []knownFormat
7494
normalizeName NameNormalizer
7595
}
7696

77-
// NewFormats creates a new formats registry seeded with the values from the default
78-
func NewFormats() Registry {
79-
//nolint:forcetypeassert
80-
return NewSeededFormats(Default.(*defaultFormats).data, nil)
81-
}
82-
83-
// NewSeededFormats creates a new formats registry
84-
func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
85-
if normalizer == nil {
86-
normalizer = DefaultNameNormalizer
87-
}
88-
// copy here, don't modify original
89-
d := append([]knownFormat(nil), seeds...)
90-
return &defaultFormats{
91-
data: d,
92-
normalizeName: normalizer,
93-
}
94-
}
95-
9697
// MapStructureHookFunc is a decode hook function for mapstructure
9798
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc {
98-
return func(from reflect.Type, to reflect.Type, obj interface{}) (interface{}, error) {
99+
return func(from reflect.Type, to reflect.Type, obj any) (any, error) {
99100
if from.Kind() != reflect.String {
100101
return obj, nil
101102
}
@@ -306,7 +307,7 @@ func (f *defaultFormats) Validates(name, data string) bool {
306307
// Parse a string into the appropriate format representation type.
307308
//
308309
// E.g. parsing a string a "date" will return a Date type.
309-
func (f *defaultFormats) Parse(name, data string) (interface{}, error) {
310+
func (f *defaultFormats) Parse(name, data string) (any, error) {
310311
f.Lock()
311312
defer f.Unlock()
312313
nme := f.normalizeName(name)

time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (t DateTime) IsZero() bool {
159159

160160
// IsUnixZerom returns whether the date time is equivalent to time.Unix(0, 0).UTC().
161161
func (t DateTime) IsUnixZero() bool {
162-
return time.Time(t) == UnixZero
162+
return time.Time(t).Equal(UnixZero)
163163
}
164164

165165
// MarshalText implements the text marshaller interface

time_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestDateTime_MarshalJSON(t *testing.T) {
217217
dt := DateTime(example.time)
218218
bb, err := dt.MarshalJSON()
219219
require.NoError(t, err)
220-
assert.EqualValues(t, esc([]byte(example.str)), bb)
220+
assert.Equal(t, esc([]byte(example.str)), bb)
221221
}
222222
}
223223
func TestDateTime_MarshalJSON_Override(t *testing.T) {
@@ -234,7 +234,7 @@ func TestDateTime_MarshalJSON_Override(t *testing.T) {
234234
dt := DateTime(example.time.UTC())
235235
bb, err := dt.MarshalJSON()
236236
require.NoError(t, err)
237-
assert.EqualValues(t, esc([]byte(example.utcStr)), bb)
237+
assert.Equal(t, esc([]byte(example.utcStr)), bb)
238238
}
239239
}
240240

0 commit comments

Comments
 (0)