From 39caed11136efd9f6d857211ad69a8f5e195854c Mon Sep 17 00:00:00 2001 From: Cool Developer Date: Fri, 23 Feb 2024 15:17:42 -0500 Subject: [PATCH] lint --- .github/workflows/lint.yml | 11 ++++++++--- .golangci.yml | 4 +--- Makefile | 9 +++++++++ backend_test.go | 2 +- goleveldb.go | 2 +- memdb.go | 2 +- memdb_iterator.go | 4 ++-- pebble.go | 2 +- prefixdb_test.go | 2 +- rocksdb.go | 4 ++-- test_helpers.go | 12 ++++++------ types.go | 2 ++ 12 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e3123b1..786ff67 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,8 +8,13 @@ on: jobs: golangci: runs-on: ubuntu-latest - container: ghcr.io/cosmos/cosmos-db/build-test:latest steps: - uses: actions/checkout@v4 - - uses: golangci/golangci-lint-action@v4.0.0 - + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: actions/setup-go@v5 + with: + go-version: "1.22" + check-latest: true + - name: run lint + run: nix develop -c make lint diff --git a/.golangci.yml b/.golangci.yml index b6f4d58..7cc6920 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - build-tags: + build-tags: - rocksdb concurrency: 4 sort-results: true @@ -9,7 +9,6 @@ run: linters: disable-all: true enable: - - depguard - dogsled - dupl - errcheck @@ -33,4 +32,3 @@ linters: - unconvert - unused - nolintlint - diff --git a/Makefile b/Makefile index 87d7e3c..6530ca0 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,17 @@ test-all: @echo "--> Running go test" @go test $(PACKAGES) -tags rocksdb,pebbledb -v +golangci_version=v1.55.0 + +#? lint-install: Install golangci-lint +lint-install: + @echo "--> Installing golangci-lint $(golangci_version)" + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) +.PHONY: lint-install + lint: @echo "--> Running linter" + $(MAKE) lint-install @golangci-lint run @go mod verify .PHONY: lint diff --git a/backend_test.go b/backend_test.go index f51aaca..f59cc2a 100644 --- a/backend_test.go +++ b/backend_test.go @@ -26,7 +26,7 @@ func init() { } func cleanupDBDir(dir, name string) { - err := os.RemoveAll(filepath.Join(dir, name) + ".db") + err := os.RemoveAll(filepath.Join(dir, name) + DBFileSuffix) if err != nil { panic(err) } diff --git a/goleveldb.go b/goleveldb.go index 218f7b3..419b395 100644 --- a/goleveldb.go +++ b/goleveldb.go @@ -40,7 +40,7 @@ func NewGoLevelDB(name string, dir string, opts Options) (*GoLevelDB, error) { } func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error) { - dbPath := filepath.Join(dir, name+".db") + dbPath := filepath.Join(dir, name+DBFileSuffix) db, err := leveldb.OpenFile(dbPath, o) if err != nil { return nil, err diff --git a/memdb.go b/memdb.go index c1fec79..6b68263 100644 --- a/memdb.go +++ b/memdb.go @@ -175,7 +175,7 @@ func (db *MemDB) NewBatch() Batch { // NewBatchWithSize implements DB. // It does the same thing as NewBatch because we can't pre-allocate memDBBatch -func (db *MemDB) NewBatchWithSize(size int) Batch { +func (db *MemDB) NewBatchWithSize(_ int) Batch { return newMemDBBatch(db) } diff --git a/memdb_iterator.go b/memdb_iterator.go index 8288809..1211550 100644 --- a/memdb_iterator.go +++ b/memdb_iterator.go @@ -105,8 +105,8 @@ func newMemDBIteratorMtxChoice(db *MemDB, start []byte, end []byte, reverse bool // Close implements Iterator. func (i *memDBIterator) Close() error { i.cancel() - for range i.ch { // drain channel - } + for range i.ch { //nolint:revive + } // drain channel i.item = nil return nil } diff --git a/pebble.go b/pebble.go index f9efa4c..106697d 100644 --- a/pebble.go +++ b/pebble.go @@ -86,7 +86,7 @@ func NewPebbleDB(name string, dir string, opts Options) (DB, error) { } } - dbPath := filepath.Join(dir, name+".db") + dbPath := filepath.Join(dir, name+DBFileSuffix) p, err := pebble.Open(dbPath, do) if err != nil { return nil, err diff --git a/prefixdb_test.go b/prefixdb_test.go index 7191a31..8e19070 100644 --- a/prefixdb_test.go +++ b/prefixdb_test.go @@ -32,7 +32,7 @@ func taskKey(i, k int) []byte { func randomValue() []byte { b := make([]byte, 16) - rand.Read(b) //nolint:gosec + rand.Read(b) //nolint:staticcheck,gosec return b } diff --git a/rocksdb.go b/rocksdb.go index 02dcdb7..ff6d6e3 100644 --- a/rocksdb.go +++ b/rocksdb.go @@ -62,7 +62,7 @@ func NewRocksDB(name string, dir string, opts Options) (*RocksDB, error) { } func NewRocksDBWithOptions(name string, dir string, opts *grocksdb.Options) (*RocksDB, error) { - dbPath := filepath.Join(dir, name+".db") + dbPath := filepath.Join(dir, name+DBFileSuffix) db, err := grocksdb.OpenDb(opts, dbPath) if err != nil { return nil, err @@ -192,7 +192,7 @@ func (db *RocksDB) NewBatch() Batch { // NewBatchWithSize implements DB. // It does the same thing as NewBatch because we can't pre-allocate rocksDBBatch -func (db *RocksDB) NewBatchWithSize(size int) Batch { +func (db *RocksDB) NewBatchWithSize(_ int) Batch { return newRocksDBBatch(db) } diff --git a/test_helpers.go b/test_helpers.go index 1e36925..eadc73a 100644 --- a/test_helpers.go +++ b/test_helpers.go @@ -22,13 +22,13 @@ MAIN_LOOP: if v >= 62 { // only 62 characters in strChars val >>= 6 continue - } else { - chars = append(chars, strChars[v]) - if len(chars) == length { - break MAIN_LOOP - } - val >>= 6 } + + chars = append(chars, strChars[v]) + if len(chars) == length { + break MAIN_LOOP + } + val >>= 6 } } diff --git a/types.go b/types.go index 5b77b3c..f358ab1 100644 --- a/types.go +++ b/types.go @@ -2,6 +2,8 @@ package db import "errors" +const DBFileSuffix = ".db" + var ( // errBatchClosed is returned when a closed or written batch is used. errBatchClosed = errors.New("batch has been written or closed")