Skip to content

Commit f1509e3

Browse files
authored
GODRIVER-3293 Upgrade golangci-lint to 1.59.1 and fix lint errors. (#1729)
1 parent cadfe96 commit f1509e3

File tree

78 files changed

+351
-756
lines changed

Some content is hidden

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

78 files changed

+351
-756
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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ repos:
5151
exclude: ^(vendor)
5252

5353
- repo: https://github.com/golangci/golangci-lint
54-
rev: v1.55.1
54+
rev: v1.59.1
5555
hooks:
5656
- id: golangci-lint

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ doc:
6565
fmt:
6666
go fmt ./...
6767

68+
# NOTE: A golangci-lint version is also pinned in .pre-commit-config.yaml. Make
69+
# sure to change it there to keep it in-sync with what's used here!
6870
.PHONY: install-golangci-lint
6971
install-golangci-lint:
70-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
72+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
7173

7274
# Lint with various GOOS and GOARCH targets to catch static analysis failures that may only affect
7375
# 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 {

0 commit comments

Comments
 (0)