Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-develope committed Feb 23, 2024
1 parent d9094fa commit 39caed1
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 21 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

- 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
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
build-tags:
build-tags:
- rocksdb
concurrency: 4
sort-results: true
Expand All @@ -9,7 +9,6 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- dupl
- errcheck
Expand All @@ -33,4 +32,3 @@ linters:
- unconvert
- unused
- nolintlint

9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion goleveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions memdb_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prefixdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 2 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 39caed1

Please sign in to comment.