Skip to content

Commit 1dce1d4

Browse files
authored
chore(linter): enable unconvert linter (#1881)
1 parent b1ea360 commit 1dce1d4

16 files changed

+38
-37
lines changed

.golangci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ linters:
2020
disable-all: true
2121
enable:
2222
- errcheck
23-
- ineffassign
24-
- gosec
2523
- gofmt
24+
- goimports
25+
- gosec
2626
- gosimple
2727
- govet
28+
- ineffassign
2829
- lll
29-
- unused
3030
- staticcheck
31-
- goimports
31+
- unconvert
32+
- unused

badger/cmd/bank.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func key(account int) []byte {
116116
func toUint64(val []byte) uint64 {
117117
u, err := strconv.ParseUint(string(val), 10, 64)
118118
y.Check(err)
119-
return uint64(u)
119+
return u
120120
}
121121

122122
func toSlice(bal uint64) []byte {
@@ -217,7 +217,7 @@ func get(txn *badger.Txn, k []byte) (*badger.Item, error) {
217217

218218
// seekTotal retrives the total of all accounts by seeking for each account key.
219219
func seekTotal(txn *badger.Txn) ([]account, error) {
220-
expected := uint64(numAccounts) * uint64(initialBal)
220+
expected := uint64(numAccounts) * initialBal
221221
var accounts []account
222222

223223
var total uint64

badger/cmd/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func showKeys(db *badger.DB, prefix []byte) error {
166166
defer txn.Discard()
167167

168168
iopt := badger.DefaultIteratorOptions
169-
iopt.Prefix = []byte(prefix)
169+
iopt.Prefix = prefix
170170
iopt.PrefetchValues = false
171171
iopt.AllVersions = opt.keyHistory
172172
iopt.InternalAccess = opt.showInternal

db2_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func TestBigValues(t *testing.T) {
388388
return err
389389
}
390390
return item.Value(func(val []byte) error {
391-
if len(val) == 0 || len(val) != len(data) || !bytes.Equal(val, []byte(data)) {
391+
if len(val) == 0 || len(val) != len(data) || !bytes.Equal(val, data) {
392392
log.Fatalf("key not found %q", len(key))
393393
}
394394
return nil
@@ -397,7 +397,7 @@ func TestBigValues(t *testing.T) {
397397
}
398398

399399
for i := 0; i < keyCount; i++ {
400-
require.NoError(t, saveByKey(key(i), []byte(data)))
400+
require.NoError(t, saveByKey(key(i), data))
401401
}
402402

403403
for i := 0; i < keyCount; i++ {
@@ -858,7 +858,7 @@ func TestMaxVersion(t *testing.T) {
858858
t.Run("normal", func(t *testing.T) {
859859
runBadgerTest(t, nil, func(t *testing.T, db *DB) {
860860
// This will create commits from 1 to N.
861-
for i := 0; i < int(N); i++ {
861+
for i := 0; i < N; i++ {
862862
txnSet(t, db, key(i), nil, 0)
863863
}
864864
ver := db.MaxVersion()

db_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ func TestGetMore(t *testing.T) {
617617
}
618618
k := data(i)
619619
txn := db.NewTransaction(false)
620-
_, err := txn.Get([]byte(k))
620+
_, err := txn.Get(k)
621621
require.Equal(t, ErrKeyNotFound, err, "should not have found k: %q", k)
622622
txn.Discard()
623623
}
@@ -1763,7 +1763,7 @@ func TestLSMOnly(t *testing.T) {
17631763
// Also test for error, when ValueThresholdSize is greater than maxBatchSize.
17641764
dopts.ValueThreshold = LSMOnlyOptions(dir).ValueThreshold
17651765
// maxBatchSize is calculated from MaxTableSize.
1766-
dopts.MemTableSize = int64(LSMOnlyOptions(dir).ValueThreshold)
1766+
dopts.MemTableSize = LSMOnlyOptions(dir).ValueThreshold
17671767
_, err = Open(dopts)
17681768
require.Error(t, err, "db creation should have been failed")
17691769
require.Contains(t, err.Error(),
@@ -2339,7 +2339,7 @@ func TestBannedPrefixes(t *testing.T) {
23392339

23402340
for _, key := range keys {
23412341
require.NoError(t, db.Update(func(txn *Txn) error {
2342-
return txn.SetEntry(NewEntry([]byte(key), []byte("value")))
2342+
return txn.SetEntry(NewEntry(key, []byte("value")))
23432343
}))
23442344
}
23452345
validate()

discard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (lf *discardStats) Update(fidu uint32, discard int64) int64 {
131131

132132
// Could not find the fid. Add the entry.
133133
idx = lf.nextEmptySlot
134-
lf.set(idx*16, uint64(fid))
134+
lf.set(idx*16, fid)
135135
lf.set(idx*16+8, uint64(discard))
136136

137137
// Move to next slot.
@@ -142,7 +142,7 @@ func (lf *discardStats) Update(fidu uint32, discard int64) int64 {
142142
lf.zeroOut()
143143

144144
sort.Sort(lf)
145-
return int64(discard)
145+
return discard
146146
}
147147

148148
func (lf *discardStats) Iterate(f func(fid, stats uint64)) {

histogram.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (histogram *histogramData) Update(value int64) {
106106
}
107107

108108
// Check if the value should be added to the "index" bin
109-
if value < int64(histogram.bins[index]) {
109+
if value < histogram.bins[index] {
110110
histogram.countPerBin[index]++
111111
break
112112
}

managed_db_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestDropAllManaged(t *testing.T) {
7474
wg.Add(1)
7575
txn := db.NewTransactionAt(math.MaxUint64, true)
7676
require.NoError(t, txn.SetEntry(NewEntry([]byte(key("key", int(i))), val(true))))
77-
require.NoError(t, txn.CommitAt(uint64(i), func(err error) {
77+
require.NoError(t, txn.CommitAt(i, func(err error) {
7878
require.NoError(t, err)
7979
wg.Done()
8080
}))
@@ -793,7 +793,7 @@ func TestZeroDiscardStats(t *testing.T) {
793793

794794
fids := db.vlog.sortedFids()
795795
for _, fid := range fids {
796-
db.vlog.discardStats.Update(uint32(fid), 1)
796+
db.vlog.discardStats.Update(fid, 1)
797797
}
798798

799799
// Ensure we have some valid fids.
@@ -821,7 +821,7 @@ func TestZeroDiscardStats(t *testing.T) {
821821
// Fill discard stats. Normally these are filled by compaction.
822822
fids := db.vlog.sortedFids()
823823
for _, fid := range fids {
824-
db.vlog.discardStats.Update(uint32(fid), 1)
824+
db.vlog.discardStats.Update(fid, 1)
825825
}
826826

827827
db.vlog.discardStats.Iterate(func(id, val uint64) { require.NotZero(t, val) })

manifest_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ func key(prefix string, i int) string {
114114
return prefix + fmt.Sprintf("%04d", i)
115115
}
116116

117-
func buildTestTable(t *testing.T, prefix string, n int, opts table.Options) *table.Table {
118-
y.AssertTrue(n <= 10000)
119-
keyValues := make([][]string, n)
120-
for i := 0; i < n; i++ {
121-
k := key(prefix, i)
122-
v := fmt.Sprintf("%d", i)
123-
keyValues[i] = []string{k, v}
124-
}
125-
return buildTable(t, keyValues, opts)
126-
}
127-
128117
// TODO - Move these to somewhere where table package can also use it.
129118
// keyValues is n by 2 where n is number of pairs.
130119
func buildTable(t *testing.T, keyValues [][]string, bopts table.Options) *table.Table {
@@ -162,6 +151,17 @@ func TestOverlappingKeyRangeError(t *testing.T) {
162151
// linter, I realized that the runCompactDef function below always returns error.
163152
t.Skip()
164153

154+
buildTestTable := func(t *testing.T, prefix string, n int, opts table.Options) *table.Table {
155+
y.AssertTrue(n <= 10000)
156+
keyValues := make([][]string, n)
157+
for i := 0; i < n; i++ {
158+
k := key(prefix, i)
159+
v := fmt.Sprintf("%d", i)
160+
keyValues[i] = []string{k, v}
161+
}
162+
return buildTable(t, keyValues, opts)
163+
}
164+
165165
dir, err := os.MkdirTemp("", "badger-test")
166166
require.NoError(t, err)
167167
defer removeDir(dir)

memtable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ loop:
487487
}
488488

489489
var vp valuePointer
490-
vp.Len = uint32(int(e.hlen) + len(e.Key) + len(e.Value) + crc32.Size)
490+
vp.Len = uint32(e.hlen + len(e.Key) + len(e.Value) + crc32.Size)
491491
read.recordOffset += vp.Len
492492

493493
vp.Offset = e.offset

0 commit comments

Comments
 (0)