Skip to content

Commit dbde20d

Browse files
committed
GODRIVER-3293 Upgrade golangci-lint to 1.59.1 and fix lint errors.
1 parent 5876554 commit dbde20d

File tree

76 files changed

+373
-780
lines changed

Some content is hidden

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

76 files changed

+373
-780
lines changed

.golangci.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
run:
22
timeout: 5m
3-
skip-dirs-use-default: false
4-
skip-dirs:
5-
- (^|/)vendor($|/)
6-
- (^|/)testdata($|/)
7-
- (^|/)etc($|/)
8-
# Disable all linters for "golang.org/x/exp/rand" package in internal/rand.
9-
- internal/rand
103

114
linters:
125
disable-all: true
@@ -35,11 +28,7 @@ linters:
3528

3629
linters-settings:
3730
errcheck:
38-
exclude: .errcheck-excludes
39-
gocritic:
40-
enabled-checks:
41-
# Detects suspicious append result assignments. E.g. "b := append(a, 1, 2, 3)"
42-
- appendAssign
31+
exclude-functions: .errcheck-excludes
4332
govet:
4433
disable:
4534
- cgocall
@@ -55,6 +44,14 @@ linters-settings:
5544
]
5645

5746
issues:
47+
exclude-dirs-use-default: false
48+
exclude-dirs:
49+
- (^|/)testdata($|/)
50+
- (^|/)etc($|/)
51+
# Disable all linters for copied third-party code.
52+
- internal/rand
53+
- internal/aws
54+
- internal/assert
5855
exclude-use-default: false
5956
exclude:
6057
# Add all default excluded issues except issues related to exported types/functions not having

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fmt:
6767

6868
.PHONY: install-golangci-lint
6969
install-golangci-lint:
70-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
70+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
7171

7272
# Lint with various GOOS and GOARCH targets to catch static analysis failures that may only affect
7373
# specific operating systems or architectures. For example, staticcheck will only check for 64-bit

bson/bsoncodec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func ExampleValueEncoder() {
2323
}
2424

2525
func ExampleValueDecoder() {
26-
var _ ValueDecoderFunc = func(dc DecodeContext, vr ValueReader, val reflect.Value) error {
26+
var _ ValueDecoderFunc = func(_ DecodeContext, vr ValueReader, val reflect.Value) error {
2727
if !val.CanSet() || val.Kind() != reflect.String {
2828
return ValueDecoderError{Name: "StringDecodeValue", Kinds: []reflect.Kind{reflect.String}, Received: val}
2929
}

bson/decimal.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ func (d Decimal128) BigInt() (*big.Int, int, error) {
7575
// Bits: 1*sign 2*ignored 14*exponent 111*significand.
7676
// Implicit 0b100 prefix in significand.
7777
exp = int(high >> 47 & (1<<14 - 1))
78-
//high = 4<<47 | d.h&(1<<47-1)
7978
// Spec says all of these values are out of range.
8079
high, low = 0, 0
8180
} else {
8281
// Bits: 1*sign 14*exponent 113*significand
8382
exp = int(high >> 49 & (1<<14 - 1))
84-
high = high & (1<<49 - 1)
83+
high &= (1<<49 - 1)
8584
}
8685
exp += MinDecimal128Exp
8786

@@ -258,7 +257,7 @@ var (
258257

259258
// ParseDecimal128FromBigInt attempts to parse the given significand and exponent into a valid Decimal128 value.
260259
func ParseDecimal128FromBigInt(bi *big.Int, exp int) (Decimal128, bool) {
261-
//copy
260+
// copy
262261
bi = new(big.Int).Set(bi)
263262

264263
q := new(big.Int)

bson/decoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func TestDecoderConfiguration(t *testing.T) {
508508
// independent of the top-level Go value type.
509509
{
510510
description: "DocumentD nested by default",
511-
configure: func(dec *Decoder) {},
511+
configure: func(_ *Decoder) {},
512512
input: bsoncore.NewDocumentBuilder().
513513
AppendDocument("myDocument", bsoncore.NewDocumentBuilder().
514514
AppendString("myString", "test value").

bson/default_value_decoders.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,8 @@ func decodeDefault(dc DecodeContext, vr ValueReader, val reflect.Value) ([]refle
12861286
var elem reflect.Value
12871287
if vDecoder == nil {
12881288
elem = val.Index(idx).Elem()
1289-
if elem.Kind() != reflect.Ptr || elem.IsNil() {
1289+
switch {
1290+
case elem.Kind() != reflect.Ptr || elem.IsNil():
12901291
valueDecoder, err := dc.LookupDecoder(elem.Type())
12911292
if err != nil {
12921293
return nil, err
@@ -1295,12 +1296,12 @@ func decodeDefault(dc DecodeContext, vr ValueReader, val reflect.Value) ([]refle
12951296
if err != nil {
12961297
return nil, newDecodeError(strconv.Itoa(idx), err)
12971298
}
1298-
} else if vr.Type() == TypeNull {
1299+
case vr.Type() == TypeNull:
12991300
if err = vr.ReadNull(); err != nil {
13001301
return nil, err
13011302
}
13021303
elem = reflect.Zero(val.Index(idx).Type())
1303-
} else {
1304+
default:
13041305
e := elem.Elem()
13051306
valueDecoder, err := dc.LookupDecoder(e.Type())
13061307
if err != nil {

bson/default_value_encoders_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ func TestDefaultValueEncoders(t *testing.T) {
10751075
},
10761076
{
10771077
"WriteArrayElement Error",
1078-
bsoncore.Array(buildDocumentArray(func(doc []byte) []byte {
1078+
bsoncore.Array(buildDocumentArray(func([]byte) []byte {
10791079
return bsoncore.AppendNullElement(nil, "foo")
10801080
})),
10811081
nil,
@@ -1085,7 +1085,7 @@ func TestDefaultValueEncoders(t *testing.T) {
10851085
},
10861086
{
10871087
"encodeValue error",
1088-
bsoncore.Array(buildDocumentArray(func(doc []byte) []byte {
1088+
bsoncore.Array(buildDocumentArray(func([]byte) []byte {
10891089
return bsoncore.AppendNullElement(nil, "foo")
10901090
})),
10911091
nil,

bson/extjson_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (ejp *extJSONParser) readValue(t Type) (*extJSONValue, error) {
303303
}
304304

305305
// remove hyphens
306-
uuidNoHyphens := strings.Replace(uuid, "-", "", -1)
306+
uuidNoHyphens := strings.ReplaceAll(uuid, "-", "")
307307
if len(uuidNoHyphens) != 32 {
308308
return nil, fmt.Errorf("$uuid value does not follow RFC 4122 format regarding length and hyphens")
309309
}

bson/extjson_writer.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,14 @@ func (ejvw *extJSONValueWriter) WriteArrayEnd() error {
567567

568568
func formatDouble(f float64) string {
569569
var s string
570-
if math.IsInf(f, 1) {
570+
switch {
571+
case math.IsInf(f, 1):
571572
s = "Infinity"
572-
} else if math.IsInf(f, -1) {
573+
case math.IsInf(f, -1):
573574
s = "-Infinity"
574-
} else if math.IsNaN(f) {
575+
case math.IsNaN(f):
575576
s = "NaN"
576-
} else {
577+
default:
577578
// Print exactly one decimalType place for integers; otherwise, print as many are necessary to
578579
// perfectly represent it.
579580
s = strconv.FormatFloat(f, 'G', -1, 64)
@@ -678,9 +679,7 @@ func (ss sortableString) Less(i, j int) bool {
678679
}
679680

680681
func (ss sortableString) Swap(i, j int) {
681-
oldI := ss[i]
682-
ss[i] = ss[j]
683-
ss[j] = oldI
682+
ss[i], ss[j] = ss[j], ss[i]
684683
}
685684

686685
func sortStringAlphebeticAscending(s string) string {

bson/json_scanner.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ func (js *jsonScanner) nextToken() (*jsonToken, error) {
8282
return js.scanString()
8383
default:
8484
// check if it's a number
85-
if c == '-' || isDigit(c) {
85+
switch {
86+
case c == '-' || isDigit(c):
8687
return js.scanNumber(c)
87-
} else if c == 't' || c == 'f' || c == 'n' {
88+
case c == 't' || c == 'f' || c == 'n':
8889
// maybe a literal
8990
return js.scanLiteral(c)
90-
} else {
91+
default:
9192
return nil, fmt.Errorf("invalid JSON input. Position: %d. Character: %c", js.pos-1, c)
9293
}
9394
}
@@ -174,7 +175,7 @@ func getu4(s []byte) rune {
174175
for _, c := range s[:4] {
175176
switch {
176177
case '0' <= c && c <= '9':
177-
c = c - '0'
178+
c -= '0'
178179
case 'a' <= c && c <= 'f':
179180
c = c - 'a' + 10
180181
case 'A' <= c && c <= 'F':
@@ -325,13 +326,14 @@ func (js *jsonScanner) scanLiteral(first byte) (*jsonToken, error) {
325326

326327
c5, err := js.readNextByte()
327328

328-
if bytes.Equal([]byte("true"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)) {
329+
switch {
330+
case bytes.Equal([]byte("true"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)):
329331
js.pos = int(math.Max(0, float64(js.pos-1)))
330332
return &jsonToken{t: jttBool, v: true, p: p}, nil
331-
} else if bytes.Equal([]byte("null"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)) {
333+
case bytes.Equal([]byte("null"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)):
332334
js.pos = int(math.Max(0, float64(js.pos-1)))
333335
return &jsonToken{t: jttNull, v: nil, p: p}, nil
334-
} else if bytes.Equal([]byte("fals"), lit) {
336+
case bytes.Equal([]byte("fals"), lit):
335337
if c5 == 'e' {
336338
c5, err = js.readNextByte()
337339

@@ -430,12 +432,13 @@ func (js *jsonScanner) scanNumber(first byte) (*jsonToken, error) {
430432
case '}', ']', ',':
431433
s = nssDone
432434
default:
433-
if isWhiteSpace(c) || errors.Is(err, io.EOF) {
435+
switch {
436+
case isWhiteSpace(c) || errors.Is(err, io.EOF):
434437
s = nssDone
435-
} else if isDigit(c) {
438+
case isDigit(c):
436439
s = nssSawIntegerDigits
437440
b.WriteByte(c)
438-
} else {
441+
default:
439442
s = nssInvalid
440443
}
441444
}
@@ -455,12 +458,13 @@ func (js *jsonScanner) scanNumber(first byte) (*jsonToken, error) {
455458
case '}', ']', ',':
456459
s = nssDone
457460
default:
458-
if isWhiteSpace(c) || errors.Is(err, io.EOF) {
461+
switch {
462+
case isWhiteSpace(c) || errors.Is(err, io.EOF):
459463
s = nssDone
460-
} else if isDigit(c) {
464+
case isDigit(c):
461465
s = nssSawFractionDigits
462466
b.WriteByte(c)
463-
} else {
467+
default:
464468
s = nssInvalid
465469
}
466470
}
@@ -490,12 +494,13 @@ func (js *jsonScanner) scanNumber(first byte) (*jsonToken, error) {
490494
case '}', ']', ',':
491495
s = nssDone
492496
default:
493-
if isWhiteSpace(c) || errors.Is(err, io.EOF) {
497+
switch {
498+
case isWhiteSpace(c) || errors.Is(err, io.EOF):
494499
s = nssDone
495-
} else if isDigit(c) {
500+
case isDigit(c):
496501
s = nssSawExponentDigits
497502
b.WriteByte(c)
498-
} else {
503+
default:
499504
s = nssInvalid
500505
}
501506
}

0 commit comments

Comments
 (0)