Skip to content

Commit 0e38ee2

Browse files
JkLondonJkLondon
andauthored
Lint fixes (#192)
* added errorlint * added all linters --------- Co-authored-by: JkLondon <ilya@mikheev.fun>
1 parent 838e03e commit 0e38ee2

File tree

14 files changed

+132
-133
lines changed

14 files changed

+132
-133
lines changed

.golangci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ linters:
2222
- unconvert
2323
- wastedassign
2424
- zerologlint
25+
- errorlint
26+
- noctx
27+
- nilerr
28+
- unused
29+
- makezero
30+
- perfsprint
31+
- gocritic
2532
disable:
26-
- errorlint #TODO: enable me
27-
- noctx #TODO: enable me
28-
- nilerr #TODO: enable me
29-
- unused #TODO: enable me
30-
- makezero #TODO: enable me
31-
- perfsprint #TODO: enable me
32-
- gocritic #TODO: enable me
3333
- contextcheck
3434
- err113
3535
- errchkjson

exp/mdbxpool/txnpool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package mdbxpool
22

33
import (
4-
"fmt"
4+
"errors"
55
"log"
66
"sync"
77
"sync/atomic"
@@ -90,7 +90,7 @@ func (p *TxnPool) BeginTxn(flags uint) (*mdbx.Txn, error) {
9090
// instead of masking flags with mdbx.Readonly an equality comparison
9191
// is necessary.
9292
if flags != mdbx.Readonly {
93-
return nil, fmt.Errorf("flag mdbx.Readonly not provided")
93+
return nil, errors.New("flag mdbx.Readonly not provided")
9494
}
9595

9696
return p.beginReadonly()

mdbx/cursor.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package mdbx
77
*/
88
import "C"
99
import (
10-
"fmt"
10+
"errors"
1111
"sync"
1212
"unsafe"
1313
)
@@ -66,6 +66,7 @@ type Cursor struct {
6666
_c *C.MDBX_cursor
6767
}
6868

69+
//nolint:gocritic // reason: false positive on dupSubExpr
6970
func openCursor(txn *Txn, db DBI) (*Cursor, error) {
7071
c := &Cursor{txn: txn}
7172
ret := C.mdbx_cursor_open(txn._txn, C.MDBX_dbi(db), &c._c)
@@ -176,10 +177,8 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
176177
// (panic or potentially garbage memory reference).
177178
if op == Set {
178179
key = setkey
179-
} else {
180-
if op != LastDup && op != FirstDup {
181-
key = castToBytes(&c.txn.key)
182-
}
180+
} else if op != LastDup && op != FirstDup {
181+
key = castToBytes(&c.txn.key)
183182
}
184183
val = castToBytes(&c.txn.val)
185184

@@ -194,6 +193,8 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
194193
// data for reference (Next, First, Last, etc).
195194
//
196195
// See mdb_cursor_get.
196+
//
197+
//nolint:gocritic // false positive on dupSubExpr
197198
func (c *Cursor) getValEmpty(op uint) error {
198199
ret := C.mdbx_cursor_get(c._c, &c.txn.key, &c.txn.val, C.MDBX_cursor_op(op))
199200
return operrno("mdbx_cursor_get", ret)
@@ -203,6 +204,8 @@ func (c *Cursor) getValEmpty(op uint) error {
203204
// reference (GetBoth, GetBothRange, etc).
204205
//
205206
// See mdb_cursor_get.
207+
//
208+
//nolint:gocritic // false positive on dupSubExpr
206209
func (c *Cursor) getVal(setkey, setval []byte, op uint) error {
207210
var k, v *C.char
208211
if len(setkey) > 0 {
@@ -244,6 +247,8 @@ func (c *Cursor) Put(key, val []byte, flags uint) error {
244247
// PutReserve returns a []byte of length n that can be written to, potentially
245248
// avoiding a memcopy. The returned byte slice is only valid in txn's thread,
246249
// before it has terminated.
250+
//
251+
//nolint:gocritic // false positive on dupSubExpr
247252
func (c *Cursor) PutReserve(key []byte, n int, flags uint) ([]byte, error) {
248253
var k *C.char
249254
if len(key) > 0 {
@@ -322,7 +327,7 @@ func CursorToPool(c *Cursor) { cursorPool.Put(c) }
322327
func CreateCursor() *Cursor {
323328
c := &Cursor{_c: C.mdbx_cursor_create(nil)}
324329
if c._c == nil {
325-
panic(fmt.Errorf("mdbx.CreateCursor: OOM"))
330+
panic(errors.New("mdbx.CreateCursor: OOM"))
326331
}
327332
return c
328333
}

mdbx/cursor_test.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ func TestCursor_Get_reverse(t *testing.T) {
566566
}
567567
}
568568

569-
//func TestCursor_PutMulti(t *testing.T) {
569+
// func TestCursor_PutMulti(t *testing.T) {
570570
// env := setup(t)
571571
//
572572
//
@@ -688,7 +688,7 @@ func TestCursor_Del(t *testing.T) {
688688

689689
k, v, err = cur.Get(nil, nil, Next)
690690
if err != nil {
691-
return fmt.Errorf("post-delete: %v", err)
691+
return fmt.Errorf("post-delete: %w", err)
692692
}
693693
item = items[2]
694694
if !bytes.Equal(k, []byte(item.k)) {
@@ -786,10 +786,10 @@ func TestDupCursor_EmptyKeyValues1(t *testing.T) {
786786
panic("nil")
787787
}
788788
if !bytes.Equal(k, []byte{1}) {
789-
panic(fmt.Sprintf("%x", k))
789+
panic(hex.EncodeToString(k))
790790
}
791791
if !bytes.Equal(v, []byte{}) {
792-
panic(fmt.Sprintf("%x", v))
792+
panic(hex.EncodeToString(k))
793793
}
794794
k, _, err = cur.Get([]byte{}, nil, Set)
795795
if err == nil {
@@ -861,10 +861,10 @@ func TestDupCursor_EmptyKeyValues2(t *testing.T) {
861861
panic("nil")
862862
}
863863
if !bytes.Equal(k, []byte{1}) {
864-
panic(fmt.Sprintf("%x", k))
864+
panic(hex.EncodeToString(k))
865865
}
866866
if !bytes.Equal(v, []byte{}) {
867-
panic(fmt.Sprintf("%x", v))
867+
panic(hex.EncodeToString(k))
868868
}
869869
k, _, err = cur.Get([]byte{}, nil, Set)
870870
if err == nil {
@@ -965,10 +965,10 @@ func TestDupCursor_EmptyKeyValues3(t *testing.T) {
965965
panic("nil")
966966
}
967967
if !bytes.Equal(k, []byte{1}) {
968-
panic(fmt.Sprintf("%x", k))
968+
panic(hex.EncodeToString(k))
969969
}
970970
if !bytes.Equal(v, []byte{}) {
971-
panic(fmt.Sprintf("%x", v))
971+
panic(hex.EncodeToString(k))
972972
}
973973
k, _, err = cur.Get([]byte{}, nil, Set)
974974
if err == nil {
@@ -1078,10 +1078,10 @@ func TestDupCursor_EmptyKeyValues(t *testing.T) {
10781078
panic("nil")
10791079
}
10801080
if !bytes.Equal(k, []byte{1}) {
1081-
panic(fmt.Sprintf("%x", k))
1081+
panic(hex.EncodeToString(v))
10821082
}
10831083
if !bytes.Equal(v, []byte{}) {
1084-
panic(fmt.Sprintf("%x", v))
1084+
panic(hex.EncodeToString(v))
10851085
}
10861086
k, _, err = cur.Get([]byte{}, nil, Set)
10871087
if err == nil {
@@ -1253,21 +1253,13 @@ func TestCursor_Del_DupSort(t *testing.T) {
12531253
panic(err)
12541254
}
12551255

1256-
//numdup, err = cur.Count()
1257-
//if err != nil {
1258-
// return err
1259-
//}
1260-
//
1261-
//if numdup != 1 {
1262-
// t.Errorf("unexpected count: %d != %d", numdup, 2)
1263-
//}
12641256
kk, vv, err := cur.Get(nil, nil, NextDup)
12651257
if err != nil {
12661258
panic(err)
12671259
}
12681260
_, _ = kk, vv //TODO: add assert
1269-
//fmt.Printf("kk: %s\n", kk)
1270-
//fmt.Printf("vv: %s\n", vv)
1261+
// fmt.Printf("kk: %s\n", kk)
1262+
// fmt.Printf("vv: %s\n", vv)
12711263

12721264
return nil
12731265
})

mdbx/env.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131

3232
EnvDefaults = C.MDBX_ENV_DEFAULTS
3333
LifoReclaim = C.MDBX_LIFORECLAIM
34-
//FixedMap = C.MDBX_FIXEDMAP // Danger zone. Map memory at a fixed address.
34+
// FixedMap = C.MDBX_FIXEDMAP // Danger zone. Map memory at a fixed address.
3535
NoSubdir = C.MDBX_NOSUBDIR // Argument to Open is a file, not a directory.
3636
Accede = C.MDBX_ACCEDE
3737
// Deprecated: always turned on since v0.12, deprecated since v0.13
@@ -45,7 +45,7 @@ const (
4545
// Deprecated: use NoStickyThreads instead because now they're sharing the same functionality
4646
NoTLS = C.MDBX_NOTLS // Danger zone. When unset reader locktable slots are tied to their thread.
4747
NoStickyThreads = C.MDBX_NOSTICKYTHREADS // Danger zone. Like MDBX_NOTLS. But also allow move RwTx between threads. Still require to call Begin/Rollback in same thread.
48-
//NoLock = C.MDBX_NOLOCK // Danger zone. MDBX does not use any locks.
48+
// NoLock = C.MDBX_NOLOCK // Danger zone. MDBX does not use any locks.
4949
NoReadahead = C.MDBX_NORDAHEAD // Disable readahead. Requires OS support.
5050
NoMemInit = C.MDBX_NOMEMINIT // Disable MDBX memory initialization.
5151
Exclusive = C.MDBX_EXCLUSIVE // Disable MDBX memory initialization.
@@ -145,6 +145,8 @@ type Env struct {
145145
// NewEnv allocates and initializes a new Env.
146146
//
147147
// See mdbx_env_create.
148+
//
149+
//nolint:gocritic // false positive on dupSubExpr
148150
func NewEnv(label Label) (*Env, error) {
149151
env := &Env{label: label}
150152
ret := C.mdbx_env_create(&env._env)
@@ -206,7 +208,7 @@ func (env *Env) FD() (uintptr, error) {
206208
// line.
207209
//
208210
// See mdbx_reader_list.
209-
//func (env *Env) ReaderList(fn func(string) error) error {
211+
// func (env *Env) ReaderList(fn func(string) error) error {
210212
// ctx, done := newMsgFunc(fn)
211213
// defer done()
212214
// if fn == nil {
@@ -254,23 +256,23 @@ func (env *Env) Close() {
254256
// CopyFD copies env to the the file descriptor fd.
255257
//
256258
// See mdbx_env_copyfd.
257-
//func (env *Env) CopyFD(fd uintptr) error {
259+
// func (env *Env) CopyFD(fd uintptr) error {
258260
// ret := C.mdbx_env_copyfd(env._env, C.mdbx_filehandle_t(fd))
259261
// return operrno("mdbx_env_copyfd", ret)
260262
//}
261263

262264
// CopyFDFlag copies env to the file descriptor fd, with options.
263265
//
264266
// See mdbx_env_copyfd2.
265-
//func (env *Env) CopyFDFlag(fd uintptr, flags uint) error {
267+
// func (env *Env) CopyFDFlag(fd uintptr, flags uint) error {
266268
// ret := C.mdbx_env_copyfd2(env._env, C.mdbx_filehandle_t(fd), C.uint(flags))
267269
// return operrno("mdbx_env_copyfd2", ret)
268270
//}
269271

270272
// Copy copies the data in env to an environment at path.
271273
//
272274
// See mdbx_env_copy.
273-
//func (env *Env) Copy(path string) error {
275+
// func (env *Env) Copy(path string) error {
274276
// cpath := C.CString(path)
275277
// defer C.free(unsafe.Pointer(cpath))
276278
// ret := C.mdbx_env_copy(env._env, cpath)
@@ -280,7 +282,7 @@ func (env *Env) Close() {
280282
// CopyFlag copies the data in env to an environment at path created with flags.
281283
//
282284
// See mdbx_env_copy2.
283-
//func (env *Env) CopyFlag(path string, flags uint) error {
285+
// func (env *Env) CopyFlag(path string, flags uint) error {
284286
// cpath := C.CString(path)
285287
// defer C.free(unsafe.Pointer(cpath))
286288
// ret := C.mdbx_env_copy2(env._env, cpath, C.uint(flags))

mdbx/env_not_win.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import "C"
1313
// if env.Open() was not previously called.
1414
//
1515
// See mdbx_env_get_path.
16-
//func (env *Env) Path() (string, error) {
16+
// func (env *Env) Path() (string, error) {
1717
// var cpath *C.char
1818
// ret := C.mdbx_env_get_path(env._env, &cpath)
1919
// if ret != success {

0 commit comments

Comments
 (0)