Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable exhaustruct linter #1034

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
63e141b
enable exhaustruct
kozyrev-m Feb 2, 2024
d4987d9
refactor initialization of 'endpoint' structure
kozyrev-m Feb 7, 2024
62a8dfc
refactor initialization of structures in internal/allocator/allocator.go
kozyrev-m Feb 9, 2024
4581e51
refactor initialization of structures in internal/backoff
kozyrev-m Feb 10, 2024
328f5da
refactor initialization of structures in internal/bind
kozyrev-m Feb 11, 2024
46235d2
edit CHANGELOG.md
kozyrev-m Feb 13, 2024
4bec025
refactor initialization of structures in internal/certificates
kozyrev-m Feb 13, 2024
5f97257
add explicit initialization of fileds of structures in internal/crede…
kozyrev-m Feb 13, 2024
db2ee7f
Merge branch 'master' into master
asmyasnikov Feb 28, 2024
7b7836f
add explicit initialization of fileds of structures in internal/grpcw…
kozyrev-m Mar 6, 2024
6f77315
add explicit initialization of fileds of structures in internal/meta
kozyrev-m Mar 10, 2024
eae4e54
switch off the exhaustruct linter for tests
kozyrev-m Mar 26, 2024
b8da064
Merge branch 'master' into master
kozyrev-m Apr 5, 2024
6f63136
again fixes in internal/meta
kozyrev-m Apr 5, 2024
80b050f
add explicit initialization of fields of structures in internal/opera…
kozyrev-m Apr 5, 2024
b27a4ac
add explicit initialization of fields of structures in internal/params
kozyrev-m Apr 5, 2024
4b7d44c
add explicit initialization of fields of structures in internal/pool
kozyrev-m Apr 6, 2024
2a19aad
add explicit initialization of fields of structures in internal/query
kozyrev-m Apr 6, 2024
ddaede2
add explicit initialization of fields of structures in internal/ratel…
kozyrev-m Apr 6, 2024
c3eedbb
add explicit initialization of fields of structures in internal/repeater
kozyrev-m Apr 8, 2024
e83898e
add explicit initialization of fields of structures in internal/scheme
kozyrev-m Apr 8, 2024
985c533
add explicit initialization of fields of structures in internal/scrip…
kozyrev-m Apr 8, 2024
e9064ef
add explicit initialization of fields of structures in internal/stack
kozyrev-m Apr 8, 2024
a85a737
add explicit initialization of fields of structures in internal/table
kozyrev-m Apr 15, 2024
2970590
add explicit initialization of fields of structures in internal/types
kozyrev-m Apr 15, 2024
bf69614
add explicit initialization of fields of structures in internal/value
kozyrev-m Apr 15, 2024
14511ab
add explicit initialization of fields of structures in internal/xcontext
kozyrev-m Apr 15, 2024
4140b14
add explicit initialization of fields of structures in internal/xerrors
kozyrev-m Apr 15, 2024
2db1efb
add explicit initialization of fields of structures in internal/xrand
kozyrev-m Apr 15, 2024
f0406f6
add explicit initialization of fields of structures in internal/xsql
kozyrev-m Apr 16, 2024
a1b0e00
add explicit initialization of fields of structures in internal/xstring
kozyrev-m Apr 16, 2024
a711da6
add explicit initialization of fields of structures in internal/xsync
kozyrev-m Apr 16, 2024
377162e
add explicit initialization of fields of structures in internal/xtest
kozyrev-m Apr 16, 2024
18b64b7
add explicit initialization of fields of structures in internal/backg…
kozyrev-m Apr 19, 2024
33bb8e5
add explicit initialization of fields of structures in internal/cmd
kozyrev-m Apr 19, 2024
447e72a
add explicit initialization of fields of structures in internal/balancer
kozyrev-m Apr 19, 2024
6c43dee
add explicit initialization of fields of structures in internal/conn
kozyrev-m Apr 19, 2024
17091a9
add explicit initialization of fields of structures in internal/coord…
kozyrev-m Apr 20, 2024
0916f1b
add explicit initialization of fields of structures in internal/disco…
kozyrev-m Apr 20, 2024
2f525ee
add explicit initialization of fields of structures in internal/topic
kozyrev-m Apr 21, 2024
9df7a9f
add explicit initialization of fields of structures in balancers/
kozyrev-m Apr 22, 2024
64786ca
add explicit initialization of fields of structures in config/
kozyrev-m Apr 22, 2024
04e6850
add explicit initialization of fields of structures in log/
kozyrev-m Apr 23, 2024
d87408a
add explicit initialization of fields of structures in retry/
kozyrev-m Apr 23, 2024
6187a25
add explicit initialization of fields of structures in scheme/
kozyrev-m Apr 23, 2024
b6ad7b8
add explicit initialization of fields of structures in sugar/
kozyrev-m Apr 23, 2024
137ff0e
add explicit initialization of fields of structures in table/
kozyrev-m Apr 24, 2024
afc8ce6
add explicit initialization of fields of structures in testutil/
kozyrev-m Apr 24, 2024
0e8696d
add explicit initialization of fields of structures in topic/
kozyrev-m Apr 24, 2024
f4da376
add explicit initialization of fields of structures in trace/
kozyrev-m Apr 24, 2024
85b78ec
fix marks from exhaustruct linter for driver.go
kozyrev-m Apr 24, 2024
3282eff
add explicit initialization of fields of structures in sql.go
kozyrev-m Apr 24, 2024
06032b3
add explicit initialization of fields of structures in examples/basic
kozyrev-m Apr 24, 2024
2cf5b70
add explicit initialization of fields of structures in examples/read_…
kozyrev-m Apr 24, 2024
90ca7de
add explicit initialization of fields of structures in examples/serve…
kozyrev-m Apr 24, 2024
01ea3c0
add explicit initialization of fields of structures in examples/topic
kozyrev-m Apr 24, 2024
c5058c4
add explicit initialization of fields of structures in tests/slo
kozyrev-m Apr 24, 2024
99d28ce
resolve conflicts
kozyrev-m May 5, 2024
299daa4
add explicit initialization of fields of structures in internal/; log…
kozyrev-m May 5, 2024
a5cc73c
fix import in internal/allocator/allocator.go
kozyrev-m May 5, 2024
47f0fc8
Merge branch 'master' into master
kozyrev-m May 13, 2024
0f3a9c0
resolve conflicts
kozyrev-m May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ linters:
- errname
- exhaustive
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
Expand Down
48 changes: 26 additions & 22 deletions internal/allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
"google.golang.org/protobuf/types/known/structpb"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the order of imported packages. Standard library packages should be imported at first place, then external packages and project internal packages as last one. Refer other files in the projects for examples.

)

type (
Expand Down Expand Up @@ -116,7 +117,7 @@ func (a *boolAllocator) Bool() (v *Ydb.Value_BoolValue) {

func (a *boolAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_BoolValue{}
*v = Ydb.Value_BoolValue{BoolValue: false}
boolPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -135,7 +136,7 @@ func (a *bytesAllocator) Bytes() (v *Ydb.Value_BytesValue) {

func (a *bytesAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_BytesValue{}
*v = Ydb.Value_BytesValue{BytesValue: []byte{}}
bytesPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -192,7 +193,7 @@ func (a *doubleAllocator) Double() (v *Ydb.Value_DoubleValue) {

func (a *doubleAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_DoubleValue{}
*v = Ydb.Value_DoubleValue{DoubleValue: 0}
doublePool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -211,7 +212,7 @@ func (a *floatAllocator) Float() (v *Ydb.Value_FloatValue) {

func (a *floatAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_FloatValue{}
*v = Ydb.Value_FloatValue{FloatValue: 0}
floatPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -230,7 +231,7 @@ func (a *int32Allocator) Int32() (v *Ydb.Value_Int32Value) {

func (a *int32Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Int32Value{}
*v = Ydb.Value_Int32Value{Int32Value: 0}
int32Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -249,7 +250,7 @@ func (a *int64Allocator) Int64() (v *Ydb.Value_Int64Value) {

func (a *int64Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Int64Value{}
*v = Ydb.Value_Int64Value{Int64Value: 0}
int64Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -287,7 +288,7 @@ func (a *low128Allocator) Low128() (v *Ydb.Value_Low_128) {

func (a *low128Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Low_128{}
*v = Ydb.Value_Low_128{Low_128: 0}
low128Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -306,7 +307,7 @@ func (a *nestedAllocator) Nested() (v *Ydb.Value_NestedValue) {

func (a *nestedAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_NestedValue{}
*v = Ydb.Value_NestedValue{NestedValue: new(Ydb.Value)}
nestedPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -325,7 +326,7 @@ func (a *nullFlagAllocator) NullFlag() (v *Ydb.Value_NullFlagValue) {

func (a *nullFlagAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_NullFlagValue{}
*v = Ydb.Value_NullFlagValue{NullFlagValue: structpb.NullValue_NULL_VALUE}
nullFlagPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -363,7 +364,10 @@ func (a *pairAllocator) Pair() (v *Ydb.ValuePair) {

func (a *pairAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.ValuePair{}
*v = Ydb.ValuePair{
Key: new(Ydb.Value),
Payload: new(Ydb.Value),
}
pairPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -428,7 +432,7 @@ func (a *textAllocator) Text() (v *Ydb.Value_TextValue) {

func (a *textAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_TextValue{}
*v = Ydb.Value_TextValue{TextValue: ""}
textPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -471,7 +475,7 @@ func (a *typeDecimalAllocator) TypeDecimal() (v *Ydb.Type_DecimalType) {

func (a *typeDecimalAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_DecimalType{}
*v = Ydb.Type_DecimalType{DecimalType: new(Ydb.DecimalType)}
typeDecimalPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -490,7 +494,7 @@ func (a *typeDictAllocator) TypeDict() (v *Ydb.Type_DictType) {

func (a *typeDictAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_DictType{}
*v = Ydb.Type_DictType{DictType: new(Ydb.DictType)}
typeDictPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -509,7 +513,7 @@ func (a *typeEmptyListAllocator) TypeEmptyList() (v *Ydb.Type_EmptyListType) {

func (a *typeEmptyListAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_EmptyListType{}
*v = Ydb.Type_EmptyListType{EmptyListType: structpb.NullValue_NULL_VALUE}
typeEmptyListPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -528,7 +532,7 @@ func (a *typeEmptyDictAllocator) TypeEmptyDict() (v *Ydb.Type_EmptyDictType) {

func (a *typeEmptyDictAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_EmptyDictType{}
*v = Ydb.Type_EmptyDictType{EmptyDictType: structpb.NullValue_NULL_VALUE}
typeEmptyDictPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -566,7 +570,7 @@ func (a *typeListAllocator) TypeList() (v *Ydb.Type_ListType) {

func (a *typeListAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_ListType{}
*v = Ydb.Type_ListType{ListType: new(Ydb.ListType)}
typeListPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -585,7 +589,7 @@ func (a *typeOptionalAllocator) TypeOptional() (v *Ydb.Type_OptionalType) {

func (a *typeOptionalAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_OptionalType{}
*v = Ydb.Type_OptionalType{OptionalType: new(Ydb.OptionalType)}
typeOptionalPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -604,7 +608,7 @@ func (a *typeStructAllocator) TypeStruct() (v *Ydb.Type_StructType) {

func (a *typeStructAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_StructType{}
*v = Ydb.Type_StructType{StructType: new(Ydb.StructType)}
typeStructPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -623,7 +627,7 @@ func (a *typeTupleAllocator) TypeTuple() (v *Ydb.Type_TupleType) {

func (a *typeTupleAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_TupleType{}
*v = Ydb.Type_TupleType{TupleType: new(Ydb.TupleType)}
typeTuplePool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -642,7 +646,7 @@ func (a *typeVariantAllocator) TypeVariant() (v *Ydb.Type_VariantType) {

func (a *typeVariantAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_VariantType{}
*v = Ydb.Type_VariantType{VariantType: new(Ydb.VariantType)}
typeVariantPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -680,7 +684,7 @@ func (a *uint32Allocator) Uint32() (v *Ydb.Value_Uint32Value) {

func (a *uint32Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Uint32Value{}
*v = Ydb.Value_Uint32Value{Uint32Value: 0}
uint32Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -699,7 +703,7 @@ func (a *uint64Allocator) Uint64() (v *Ydb.Value_Uint64Value) {

func (a *uint64Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Uint64Value{}
*v = Ydb.Value_Uint64Value{Uint64Value: 0}
uint64Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down
5 changes: 4 additions & 1 deletion internal/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func WithSeed(seed int64) option {

func New(opts ...option) logBackoff {
b := logBackoff{
r: xrand.New(xrand.WithLock()),
slotDuration: time.Duration(0),
ceiling: 0,
jitterLimit: 0,
r: xrand.New(xrand.WithLock()),
}
for _, o := range opts {
if o != nil {
Expand Down
68 changes: 35 additions & 33 deletions internal/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{gte: 0, lte: time.Second},
{gte: 0, lte: 2 * time.Second},
{gte: 0, lte: 4 * time.Second},
{gte: 0, lte: 8 * time.Second},
{gte: 0, lte: 8 * time.Second},
{gte: 0, lte: 8 * time.Second},
{gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: time.Second},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is a linter required for tests too?
this code is too detailed for tests

Copy link
Author

@kozyrev-m kozyrev-m Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.
Exhaustruct linter checks all files, including tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you disable this linter for tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try if possible.
Now, I don't know how to switch off the linter for tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use something like this

issues:
  exclude-rules:
    - path: _test.go
      linters:
        - exhaustruct

{eq: 0, gte: 0, lte: 2 * time.Second},
{eq: 0, gte: 0, lte: 4 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
{eq: 0, gte: 0, lte: 8 * time.Second},
},
seeds: 1000,
},
Expand All @@ -78,13 +78,13 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{gte: 500 * time.Millisecond, lte: time.Second},
{gte: 1 * time.Second, lte: 2 * time.Second},
{gte: 2 * time.Second, lte: 4 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 500 * time.Millisecond, lte: time.Second},
{eq: 0, gte: 1 * time.Second, lte: 2 * time.Second},
{eq: 0, gte: 2 * time.Second, lte: 4 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
{eq: 0, gte: 4 * time.Second, lte: 8 * time.Second},
},
seeds: 1000,
},
Expand All @@ -96,14 +96,15 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{eq: time.Second},
{eq: 2 * time.Second},
{eq: 4 * time.Second},
{eq: 8 * time.Second},
{eq: 8 * time.Second},
{eq: 8 * time.Second},
{eq: 8 * time.Second},
{eq: time.Second, gte: 0, lte: 0},
{eq: 2 * time.Second, gte: 0, lte: 0},
{eq: 4 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
},
seeds: 0,
},
{
backoff: New(
Expand All @@ -113,19 +114,20 @@ func TestLogBackoff(t *testing.T) {
WithSeed(0),
),
exp: []exp{
{eq: time.Second},
{eq: 2 * time.Second},
{eq: 4 * time.Second},
{eq: 8 * time.Second},
{eq: 16 * time.Second},
{eq: 32 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: 64 * time.Second},
{eq: time.Second, gte: 0, lte: 0},
{eq: 2 * time.Second, gte: 0, lte: 0},
{eq: 4 * time.Second, gte: 0, lte: 0},
{eq: 8 * time.Second, gte: 0, lte: 0},
{eq: 16 * time.Second, gte: 0, lte: 0},
{eq: 32 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
{eq: 64 * time.Second, gte: 0, lte: 0},
},
seeds: 0,
},
} {
t.Run("", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal/bind/numeric_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ func (m NumericArgs) RewriteQuery(sql string, args ...interface{}) (
) {
l := &sqlLexer{
src: sql,
start: 0,
pos: 0,
nested: 0,
stateFn: numericArgsStateFn,
rawStateFn: numericArgsStateFn,
parts: []interface{}{},
}

for l.stateFn != nil {
Expand Down
Loading
Loading