Skip to content

Commit 5e714b3

Browse files
authored
GODRIVER-2156 Enable structcheck and varcheck linters. (#797)
1 parent c2cbeca commit 5e714b3

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

.golangci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ linters:
1616
- nakedret
1717
- revive
1818
- staticcheck
19-
# - structcheck
19+
- structcheck
2020
- typecheck
2121
- unused
2222
- unconvert
2323
# - unparam
24-
# - varcheck
24+
- varcheck
2525

2626
linters-settings:
2727
errcheck:
@@ -69,6 +69,7 @@ issues:
6969
- path: x/mongo/driver/auth/internal/awsv4
7070
linters:
7171
- unused
72+
- structcheck
7273
# Disable "unused" linter for "crypt.go" because the linter doesn't work correctly without
7374
# enabling CGO.
7475
- path: x/mongo/driver/crypt.go

bson/bsoncodec/struct_codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func (sc *StructCodec) describeStruct(r *Registry, t reflect.Type) (*structDescr
560560
}
561561
dominant, ok := dominantField(fields[i : i+advance])
562562
if !ok || !sc.OverwriteDuplicatedInlinedFields {
563-
return nil, fmt.Errorf("struct %s) duplicated key %s", t.String(), name)
563+
return nil, fmt.Errorf("struct %s has duplicated key %s", t.String(), name)
564564
}
565565
sd.fl = append(sd.fl, dominant)
566566
sd.fm[name] = dominant

bson/mgocompat/bson_test.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -725,37 +725,37 @@ func TestMarshalErrorItems(t *testing.T) {
725725
// Unmarshalling error cases.
726726

727727
type unmarshalErrorType struct {
728-
obj interface{}
729-
data string
730-
error string
728+
obj interface{}
729+
data string
731730
}
732731

733732
var unmarshalErrorItems = []unmarshalErrorType{
734733
// Tag name conflicts with existing parameter.
735-
{&structWithDupKeys{},
736-
"\x10name\x00\x08\x00\x00\x00",
737-
"Duplicated key 'name' in struct bson_test.structWithDupKeys"},
738-
739-
{nil,
740-
"\xEEname\x00",
741-
"Unknown element kind \\(0xEE\\)"},
742-
743-
{struct{ Name bool }{},
744-
"\x10name\x00\x08\x00\x00\x00",
745-
"unmarshal can't deal with struct values. Use a pointer"},
746-
747-
{123,
748-
"\x10name\x00\x08\x00\x00\x00",
749-
"unmarshal needs a map or a pointer to a struct"},
750-
751-
{nil,
752-
"\x08\x62\x00\x02",
753-
"encoded boolean must be 1 or 0, found 2"},
754-
734+
{
735+
obj: &structWithDupKeys{},
736+
data: "\x10name\x00\x08\x00\x00\x00",
737+
},
738+
{
739+
obj: nil,
740+
data: "\xEEname\x00",
741+
},
742+
{
743+
obj: struct{ Name bool }{},
744+
data: "\x10name\x00\x08\x00\x00\x00",
745+
},
746+
{
747+
obj: 123,
748+
data: "\x10name\x00\x08\x00\x00\x00",
749+
},
750+
{
751+
obj: nil,
752+
data: "\x08\x62\x00\x02",
753+
},
755754
// Non-string and not numeric map key.
756-
{map[bool]interface{}{true: 1},
757-
"\x10true\x00\x01\x00\x00\x00",
758-
"BSON map must have string or decimal keys. Got: map\\[bool\\]interface \\{\\}"},
755+
{
756+
obj: map[bool]interface{}{true: 1},
757+
data: "\x10true\x00\x01\x00\x00\x00",
758+
},
759759
}
760760

761761
func TestUnmarshalErrorItems(t *testing.T) {
@@ -778,28 +778,28 @@ func TestUnmarshalErrorItems(t *testing.T) {
778778
}
779779

780780
type unmarshalRawErrorType struct {
781-
obj interface{}
782-
raw bson.RawValue
783-
error string
781+
obj interface{}
782+
raw bson.RawValue
784783
}
785784

786785
var unmarshalRawErrorItems = []unmarshalRawErrorType{
787786
// Tag name conflicts with existing parameter.
788-
{&structWithDupKeys{},
789-
bson.RawValue{Type: 0x03, Value: []byte("\x10byte\x00\x08\x00\x00\x00")},
790-
"Duplicated key 'name' in struct bson_test.structWithDupKeys"},
791-
792-
{&struct{}{},
793-
bson.RawValue{Type: 0xEE, Value: []byte{}},
794-
"Unknown element kind \\(0xEE\\)"},
795-
796-
{struct{ Name bool }{},
797-
bson.RawValue{Type: 0x10, Value: []byte("\x08\x00\x00\x00")},
798-
"raw Unmarshal can't deal with struct values. Use a pointer"},
799-
800-
{123,
801-
bson.RawValue{Type: 0x10, Value: []byte("\x08\x00\x00\x00")},
802-
"raw Unmarshal needs a map or a valid pointer"},
787+
{
788+
obj: &structWithDupKeys{},
789+
raw: bson.RawValue{Type: 0x03, Value: []byte("\x10byte\x00\x08\x00\x00\x00")},
790+
},
791+
{
792+
obj: &struct{}{},
793+
raw: bson.RawValue{Type: 0xEE, Value: []byte{}},
794+
},
795+
{
796+
obj: struct{ Name bool }{},
797+
raw: bson.RawValue{Type: 0x10, Value: []byte("\x08\x00\x00\x00")},
798+
},
799+
{
800+
obj: 123,
801+
raw: bson.RawValue{Type: 0x10, Value: []byte("\x08\x00\x00\x00")},
802+
},
803803
}
804804

805805
func TestUnmarshalRawErrorItems(t *testing.T) {

0 commit comments

Comments
 (0)