From ee67e34519a87a513731892d60c6ab97855f0c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Corbi=C3=A8re?= Date: Tue, 3 Apr 2018 12:23:28 +0200 Subject: [PATCH] Fix lint errors (#190) * use increment and decrement operators. * remove unnecessary else branches. * fix receiver names. * remove omittable code. * fix dot imports. --- autofile/autofile.go | 7 +++--- autofile/group.go | 48 ++++++++++++++++++------------------------ autofile/group_test.go | 2 +- clist/clist.go | 4 ++-- clist/clist_test.go | 6 +++--- common/async_test.go | 6 +++--- common/bit_array.go | 3 +-- common/colors.go | 3 +-- common/errors.go | 7 +++--- common/io.go | 3 +-- common/os.go | 11 +++++----- common/service.go | 13 +++++------- common/string.go | 3 +-- common/word.go | 3 +-- db/backend_test.go | 2 +- db/common_test.go | 44 +++++++++++++++++++------------------- db/db_test.go | 12 +++++------ db/go_level_db.go | 13 ++++++------ db/go_level_db_test.go | 2 +- db/mem_db.go | 2 +- db/types.go | 3 +-- db/util.go | 28 ++++++++++++------------ db/util_test.go | 10 ++++----- events/events.go | 8 +++---- events/events_test.go | 4 ++-- merkle/simple_proof.go | 11 +++++----- test/mutate.go | 8 +++---- 27 files changed, 121 insertions(+), 145 deletions(-) diff --git a/autofile/autofile.go b/autofile/autofile.go index 05fb0d677..790be5224 100644 --- a/autofile/autofile.go +++ b/autofile/autofile.go @@ -5,7 +5,7 @@ import ( "sync" "time" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) /* AutoFile usage @@ -44,7 +44,7 @@ type AutoFile struct { func OpenAutoFile(path string) (af *AutoFile, err error) { af = &AutoFile{ - ID: RandStr(12) + ":" + path, + ID: cmn.RandStr(12) + ":" + path, Path: path, ticker: time.NewTicker(autoFileOpenDuration), } @@ -129,9 +129,8 @@ func (af *AutoFile) Size() (int64, error) { if err != nil { if err == os.ErrNotExist { return 0, nil - } else { - return -1, err } + return -1, err } } stat, err := af.file.Stat() diff --git a/autofile/group.go b/autofile/group.go index f2d0f2bae..652c33310 100644 --- a/autofile/group.go +++ b/autofile/group.go @@ -15,7 +15,7 @@ import ( "sync" "time" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) const ( @@ -54,7 +54,7 @@ The Group can also be used to binary-search for some line, assuming that marker lines are written occasionally. */ type Group struct { - BaseService + cmn.BaseService ID string Head *AutoFile // The head AutoFile to write to @@ -90,7 +90,7 @@ func OpenGroup(headPath string) (g *Group, err error) { minIndex: 0, maxIndex: 0, } - g.BaseService = *NewBaseService(nil, "Group", g) + g.BaseService = *cmn.NewBaseService(nil, "Group", g) gInfo := g.readGroupInfo() g.minIndex = gInfo.MinIndex @@ -267,7 +267,7 @@ func (g *Group) RotateFile() { panic(err) } - g.maxIndex += 1 + g.maxIndex++ } // NewReader returns a new group reader. @@ -277,9 +277,8 @@ func (g *Group) NewReader(index int) (*GroupReader, error) { err := r.SetIndex(index) if err != nil { return nil, err - } else { - return r, nil } + return r, nil } // Returns -1 if line comes after, 0 if found, 1 if line comes before. @@ -311,9 +310,8 @@ func (g *Group) Search(prefix string, cmp SearchFunc) (*GroupReader, bool, error if err != nil { r.Close() return nil, false, err - } else { - return r, match, err } + return r, match, err } // Read starting roughly at the middle file, @@ -349,9 +347,8 @@ func (g *Group) Search(prefix string, cmp SearchFunc) (*GroupReader, bool, error if err != nil { r.Close() return nil, false, err - } else { - return r, true, err } + return r, true, err } else { // We passed it maxIndex = curIndex - 1 @@ -429,9 +426,8 @@ GROUP_LOOP: if err == io.EOF { if found { return match, found, nil - } else { - continue GROUP_LOOP } + continue GROUP_LOOP } else if err != nil { return "", false, err } @@ -442,9 +438,8 @@ GROUP_LOOP: if r.CurIndex() > i { if found { return match, found, nil - } else { - continue GROUP_LOOP } + continue GROUP_LOOP } } } @@ -520,7 +515,7 @@ func (g *Group) readGroupInfo() GroupInfo { minIndex, maxIndex = 0, 0 } else { // Otherwise, the head file is 1 greater - maxIndex += 1 + maxIndex++ } return GroupInfo{minIndex, maxIndex, totalSize, headSize} } @@ -528,9 +523,8 @@ func (g *Group) readGroupInfo() GroupInfo { func filePathForIndex(headPath string, index int, maxIndex int) string { if index == maxIndex { return headPath - } else { - return fmt.Sprintf("%v.%03d", headPath, index) } + return fmt.Sprintf("%v.%03d", headPath, index) } //-------------------------------------------------------------------------------- @@ -567,9 +561,8 @@ func (gr *GroupReader) Close() error { gr.curFile = nil gr.curLine = nil return err - } else { - return nil } + return nil } // Read implements io.Reader, reading bytes from the current Reader @@ -598,10 +591,10 @@ func (gr *GroupReader) Read(p []byte) (n int, err error) { if err == io.EOF { if n >= lenP { return n, nil - } else { // Open the next file - if err1 := gr.openFile(gr.curIndex + 1); err1 != nil { - return n, err1 - } + } + // Open the next file + if err1 := gr.openFile(gr.curIndex + 1); err1 != nil { + return n, err1 } } else if err != nil { return n, err @@ -643,10 +636,9 @@ func (gr *GroupReader) ReadLine() (string, error) { } if len(bytesRead) > 0 && bytesRead[len(bytesRead)-1] == byte('\n') { return linePrefix + string(bytesRead[:len(bytesRead)-1]), nil - } else { - linePrefix += string(bytesRead) - continue } + linePrefix += string(bytesRead) + continue } else if err != nil { return "", err } @@ -726,11 +718,11 @@ func (gr *GroupReader) SetIndex(index int) error { func MakeSimpleSearchFunc(prefix string, target int) SearchFunc { return func(line string) (int, error) { if !strings.HasPrefix(line, prefix) { - return -1, errors.New(Fmt("Marker line did not have prefix: %v", prefix)) + return -1, errors.New(cmn.Fmt("Marker line did not have prefix: %v", prefix)) } i, err := strconv.Atoi(line[len(prefix):]) if err != nil { - return -1, errors.New(Fmt("Failed to parse marker line: %v", err.Error())) + return -1, errors.New(cmn.Fmt("Failed to parse marker line: %v", err.Error())) } if target < i { return 1, nil diff --git a/autofile/group_test.go b/autofile/group_test.go index c4f68f057..1a1111961 100644 --- a/autofile/group_test.go +++ b/autofile/group_test.go @@ -175,7 +175,7 @@ func TestSearch(t *testing.T) { if !strings.HasPrefix(line, fmt.Sprintf("INFO %v ", cur)) { t.Fatalf("Unexpected INFO #. Expected %v got:\n%v", cur, line) } - cur += 1 + cur++ } gr.Close() } diff --git a/clist/clist.go b/clist/clist.go index 28d771a28..ccb1f5777 100644 --- a/clist/clist.go +++ b/clist/clist.go @@ -316,7 +316,7 @@ func (l *CList) PushBack(v interface{}) *CElement { l.wg.Done() close(l.waitCh) } - l.len += 1 + l.len++ // Modify the tail if l.tail == nil { @@ -357,7 +357,7 @@ func (l *CList) Remove(e *CElement) interface{} { } // Update l.len - l.len -= 1 + l.len-- // Connect next/prev and set head/tail if prev == nil { diff --git a/clist/clist_test.go b/clist/clist_test.go index 31f821653..6171f1a39 100644 --- a/clist/clist_test.go +++ b/clist/clist_test.go @@ -122,7 +122,7 @@ func _TestGCRandom(t *testing.T) { v.Int = i l.PushBack(v) runtime.SetFinalizer(v, func(v *value) { - gcCount += 1 + gcCount++ }) } @@ -177,10 +177,10 @@ func TestScanRightDeleteRandom(t *testing.T) { } if el == nil { el = l.FrontWait() - restartCounter += 1 + restartCounter++ } el = el.Next() - counter += 1 + counter++ } fmt.Printf("Scanner %v restartCounter: %v counter: %v\n", scannerID, restartCounter, counter) }(i) diff --git a/common/async_test.go b/common/async_test.go index 8d41ec35a..9f060ca2d 100644 --- a/common/async_test.go +++ b/common/async_test.go @@ -33,13 +33,13 @@ func TestParallel(t *testing.T) { taskResult, ok := trs.LatestResult(i) if !ok { assert.Fail(t, "Task #%v did not complete.", i) - failedTasks += 1 + failedTasks++ } else if taskResult.Error != nil { assert.Fail(t, "Task should not have errored but got %v", taskResult.Error) - failedTasks += 1 + failedTasks++ } else if !assert.Equal(t, -1*i, taskResult.Value.(int)) { assert.Fail(t, "Task should have returned %v but got %v", -1*i, taskResult.Value.(int)) - failedTasks += 1 + failedTasks++ } else { // Good! } diff --git a/common/bit_array.go b/common/bit_array.go index a3a87ccab..ea6a6ee1f 100644 --- a/common/bit_array.go +++ b/common/bit_array.go @@ -168,9 +168,8 @@ func (bA *BitArray) Sub(o *BitArray) *BitArray { } } return c - } else { - return bA.and(o.Not()) // Note degenerate case where o == nil } + return bA.and(o.Not()) // Note degenerate case where o == nil } func (bA *BitArray) IsEmpty() bool { diff --git a/common/colors.go b/common/colors.go index 776b22e2e..85e592248 100644 --- a/common/colors.go +++ b/common/colors.go @@ -38,9 +38,8 @@ const ( func treat(s string, color string) string { if len(s) > 2 && s[:2] == "\x1b[" { return s - } else { - return color + s + ANSIReset } + return color + s + ANSIReset } func treatAll(color string, args ...interface{}) string { diff --git a/common/errors.go b/common/errors.go index 52c45c799..c5efae9cf 100644 --- a/common/errors.go +++ b/common/errors.go @@ -13,11 +13,10 @@ func ErrorWrap(cause interface{}, format string, args ...interface{}) Error { msg := Fmt(format, args...) if causeCmnError, ok := cause.(*cmnError); ok { return causeCmnError.TraceFrom(1, msg) - } else { - // NOTE: cause may be nil. - // NOTE: do not use causeCmnError here, not the same as nil. - return newError(msg, cause, cause).Stacktrace() } + // NOTE: cause may be nil. + // NOTE: do not use causeCmnError here, not the same as nil. + return newError(msg, cause, cause).Stacktrace() } //---------------------------------------- diff --git a/common/io.go b/common/io.go index 378c19fc6..fa0443e09 100644 --- a/common/io.go +++ b/common/io.go @@ -20,9 +20,8 @@ func (pr *PrefixedReader) Read(p []byte) (n int, err error) { read := copy(p, pr.Prefix) pr.Prefix = pr.Prefix[read:] return read, nil - } else { - return pr.reader.Read(p) } + return pr.reader.Read(p) } // NOTE: Not goroutine safe diff --git a/common/os.go b/common/os.go index f1e07115c..60a4217aa 100644 --- a/common/os.go +++ b/common/os.go @@ -183,11 +183,10 @@ func Prompt(prompt string, defaultValue string) (string, error) { line, err := reader.ReadString('\n') if err != nil { return defaultValue, err - } else { - line = strings.TrimSpace(line) - if line == "" { - return defaultValue, nil - } - return line, nil } + line = strings.TrimSpace(line) + if line == "" { + return defaultValue, nil + } + return line, nil } diff --git a/common/service.go b/common/service.go index 2502d671c..2f90fa4f9 100644 --- a/common/service.go +++ b/common/service.go @@ -125,9 +125,8 @@ func (bs *BaseService) Start() error { if atomic.LoadUint32(&bs.stopped) == 1 { bs.Logger.Error(Fmt("Not starting %v -- already stopped", bs.name), "impl", bs.impl) return ErrAlreadyStopped - } else { - bs.Logger.Info(Fmt("Starting %v", bs.name), "impl", bs.impl) } + bs.Logger.Info(Fmt("Starting %v", bs.name), "impl", bs.impl) err := bs.impl.OnStart() if err != nil { // revert flag @@ -135,10 +134,9 @@ func (bs *BaseService) Start() error { return err } return nil - } else { - bs.Logger.Debug(Fmt("Not starting %v -- already started", bs.name), "impl", bs.impl) - return ErrAlreadyStarted } + bs.Logger.Debug(Fmt("Not starting %v -- already started", bs.name), "impl", bs.impl) + return ErrAlreadyStarted } // OnStart implements Service by doing nothing. @@ -154,10 +152,9 @@ func (bs *BaseService) Stop() error { bs.impl.OnStop() close(bs.quit) return nil - } else { - bs.Logger.Debug(Fmt("Stopping %v (ignoring: already stopped)", bs.name), "impl", bs.impl) - return ErrAlreadyStopped } + bs.Logger.Debug(Fmt("Stopping %v (ignoring: already stopped)", bs.name), "impl", bs.impl) + return ErrAlreadyStopped } // OnStop implements Service by doing nothing. diff --git a/common/string.go b/common/string.go index dfa262d3f..0e2231e91 100644 --- a/common/string.go +++ b/common/string.go @@ -10,9 +10,8 @@ import ( var Fmt = func(format string, a ...interface{}) string { if len(a) == 0 { return format - } else { - return fmt.Sprintf(format, a...) } + return fmt.Sprintf(format, a...) } // IsHex returns true for non-empty hex-string prefixed with "0x" diff --git a/common/word.go b/common/word.go index 4072482b8..a5b841f55 100644 --- a/common/word.go +++ b/common/word.go @@ -72,9 +72,8 @@ func (tuple Tuple256) Compare(other Tuple256) int { firstCompare := tuple.First.Compare(other.First) if firstCompare == 0 { return tuple.Second.Compare(other.Second) - } else { - return firstCompare } + return firstCompare } func Tuple256Split(t Tuple256) (Word256, Word256) { diff --git a/db/backend_test.go b/db/backend_test.go index 80fbbb140..c407b214f 100644 --- a/db/backend_test.go +++ b/db/backend_test.go @@ -47,7 +47,7 @@ func testBackendGetSetDelete(t *testing.T, backend DBBackendType) { } func TestBackendsGetSetDelete(t *testing.T) { - for dbType, _ := range backends { + for dbType := range backends { testBackendGetSetDelete(t, dbType) } } diff --git a/db/common_test.go b/db/common_test.go index 7f9d10e9b..1d8d52c5f 100644 --- a/db/common_test.go +++ b/db/common_test.go @@ -82,73 +82,73 @@ func (mdb *mockDB) Mutex() *sync.Mutex { } func (mdb *mockDB) Get([]byte) []byte { - mdb.calls["Get"] += 1 + mdb.calls["Get"]++ return nil } func (mdb *mockDB) Has([]byte) bool { - mdb.calls["Has"] += 1 + mdb.calls["Has"]++ return false } func (mdb *mockDB) Set([]byte, []byte) { - mdb.calls["Set"] += 1 + mdb.calls["Set"]++ } func (mdb *mockDB) SetSync([]byte, []byte) { - mdb.calls["SetSync"] += 1 + mdb.calls["SetSync"]++ } func (mdb *mockDB) SetNoLock([]byte, []byte) { - mdb.calls["SetNoLock"] += 1 + mdb.calls["SetNoLock"]++ } func (mdb *mockDB) SetNoLockSync([]byte, []byte) { - mdb.calls["SetNoLockSync"] += 1 + mdb.calls["SetNoLockSync"]++ } func (mdb *mockDB) Delete([]byte) { - mdb.calls["Delete"] += 1 + mdb.calls["Delete"]++ } func (mdb *mockDB) DeleteSync([]byte) { - mdb.calls["DeleteSync"] += 1 + mdb.calls["DeleteSync"]++ } func (mdb *mockDB) DeleteNoLock([]byte) { - mdb.calls["DeleteNoLock"] += 1 + mdb.calls["DeleteNoLock"]++ } func (mdb *mockDB) DeleteNoLockSync([]byte) { - mdb.calls["DeleteNoLockSync"] += 1 + mdb.calls["DeleteNoLockSync"]++ } func (mdb *mockDB) Iterator(start, end []byte) Iterator { - mdb.calls["Iterator"] += 1 + mdb.calls["Iterator"]++ return &mockIterator{} } func (mdb *mockDB) ReverseIterator(start, end []byte) Iterator { - mdb.calls["ReverseIterator"] += 1 + mdb.calls["ReverseIterator"]++ return &mockIterator{} } func (mdb *mockDB) Close() { - mdb.calls["Close"] += 1 + mdb.calls["Close"]++ } func (mdb *mockDB) NewBatch() Batch { - mdb.calls["NewBatch"] += 1 + mdb.calls["NewBatch"]++ return &memBatch{db: mdb} } func (mdb *mockDB) Print() { - mdb.calls["Print"] += 1 + mdb.calls["Print"]++ fmt.Printf("mockDB{%v}", mdb.Stats()) } func (mdb *mockDB) Stats() map[string]string { - mdb.calls["Stats"] += 1 + mdb.calls["Stats"]++ res := make(map[string]string) for key, count := range mdb.calls { @@ -162,24 +162,24 @@ func (mdb *mockDB) Stats() map[string]string { type mockIterator struct{} -func (_ mockIterator) Domain() (start []byte, end []byte) { +func (mockIterator) Domain() (start []byte, end []byte) { return nil, nil } -func (_ mockIterator) Valid() bool { +func (mockIterator) Valid() bool { return false } -func (_ mockIterator) Next() { +func (mockIterator) Next() { } -func (_ mockIterator) Key() []byte { +func (mockIterator) Key() []byte { return nil } -func (_ mockIterator) Value() []byte { +func (mockIterator) Value() []byte { return nil } -func (_ mockIterator) Close() { +func (mockIterator) Close() { } diff --git a/db/db_test.go b/db/db_test.go index 3d6ac38c4..a56901016 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -8,7 +8,7 @@ import ( ) func TestDBIteratorSingleKey(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) db.SetSync(bz("1"), bz("value_1")) @@ -26,7 +26,7 @@ func TestDBIteratorSingleKey(t *testing.T) { } func TestDBIteratorTwoKeys(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) db.SetSync(bz("1"), bz("value_1")) @@ -52,7 +52,7 @@ func TestDBIteratorTwoKeys(t *testing.T) { } func TestDBIteratorMany(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) @@ -76,7 +76,7 @@ func TestDBIteratorMany(t *testing.T) { } func TestDBIteratorEmpty(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) itr := db.Iterator(nil, nil) @@ -87,7 +87,7 @@ func TestDBIteratorEmpty(t *testing.T) { } func TestDBIteratorEmptyBeginAfter(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) itr := db.Iterator(bz("1"), nil) @@ -98,7 +98,7 @@ func TestDBIteratorEmptyBeginAfter(t *testing.T) { } func TestDBIteratorNonemptyBeginAfter(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) db.SetSync(bz("1"), bz("value_1")) diff --git a/db/go_level_db.go b/db/go_level_db.go index 55ca36c39..9ff162e38 100644 --- a/db/go_level_db.go +++ b/db/go_level_db.go @@ -10,7 +10,7 @@ import ( "github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/opt" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) func init() { @@ -46,9 +46,8 @@ func (db *GoLevelDB) Get(key []byte) []byte { if err != nil { if err == errors.ErrNotFound { return nil - } else { - panic(err) } + panic(err) } return res } @@ -64,7 +63,7 @@ func (db *GoLevelDB) Set(key []byte, value []byte) { value = nonNilBytes(value) err := db.db.Put(key, value, nil) if err != nil { - PanicCrisis(err) + cmn.PanicCrisis(err) } } @@ -74,7 +73,7 @@ func (db *GoLevelDB) SetSync(key []byte, value []byte) { value = nonNilBytes(value) err := db.db.Put(key, value, &opt.WriteOptions{Sync: true}) if err != nil { - PanicCrisis(err) + cmn.PanicCrisis(err) } } @@ -83,7 +82,7 @@ func (db *GoLevelDB) Delete(key []byte) { key = nonNilBytes(key) err := db.db.Delete(key, nil) if err != nil { - PanicCrisis(err) + cmn.PanicCrisis(err) } } @@ -92,7 +91,7 @@ func (db *GoLevelDB) DeleteSync(key []byte) { key = nonNilBytes(key) err := db.db.Delete(key, &opt.WriteOptions{Sync: true}) if err != nil { - PanicCrisis(err) + cmn.PanicCrisis(err) } } diff --git a/db/go_level_db_test.go b/db/go_level_db_test.go index 88b6730f3..266add8b5 100644 --- a/db/go_level_db_test.go +++ b/db/go_level_db_test.go @@ -30,7 +30,7 @@ func BenchmarkRandomReadsWrites(b *testing.B) { // Write something { idx := (int64(cmn.RandInt()) % numItems) - internal[idx] += 1 + internal[idx]++ val := internal[idx] idxBytes := int642Bytes(int64(idx)) valBytes := int642Bytes(int64(val)) diff --git a/db/mem_db.go b/db/mem_db.go index 5439d6789..2d802947c 100644 --- a/db/mem_db.go +++ b/db/mem_db.go @@ -235,7 +235,7 @@ func (itr *memDBIterator) assertIsValid() { func (db *MemDB) getSortedKeys(start, end []byte, reverse bool) []string { keys := []string{} - for key, _ := range db.db { + for key := range db.db { if IsKeyInDomain([]byte(key), start, end, false) { keys = append(keys, key) } diff --git a/db/types.go b/db/types.go index 45146942e..ad78859a7 100644 --- a/db/types.go +++ b/db/types.go @@ -129,7 +129,6 @@ func bz(s string) []byte { func nonNilBytes(bz []byte) []byte { if bz == nil { return []byte{} - } else { - return bz } + return bz } diff --git a/db/util.go b/db/util.go index ecb392dd6..1ad5002d6 100644 --- a/db/util.go +++ b/db/util.go @@ -21,14 +21,13 @@ func cpIncr(bz []byte) (ret []byte) { ret = cp(bz) for i := len(bz) - 1; i >= 0; i-- { if ret[i] < byte(0xFF) { - ret[i] += 1 + ret[i]++ return - } else { - ret[i] = byte(0x00) - if i == 0 { - // Overflow - return nil - } + } + ret[i] = byte(0x00) + if i == 0 { + // Overflow + return nil } } return nil @@ -44,13 +43,12 @@ func IsKeyInDomain(key, start, end []byte, isReverse bool) bool { return false } return true - } else { - if start != nil && bytes.Compare(start, key) < 0 { - return false - } - if end != nil && bytes.Compare(key, end) <= 0 { - return false - } - return true } + if start != nil && bytes.Compare(start, key) < 0 { + return false + } + if end != nil && bytes.Compare(key, end) <= 0 { + return false + } + return true } diff --git a/db/util_test.go b/db/util_test.go index 854448af3..44f1f9f73 100644 --- a/db/util_test.go +++ b/db/util_test.go @@ -7,7 +7,7 @@ import ( // Empty iterator for empty db. func TestPrefixIteratorNoMatchNil(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) itr := IteratePrefix(db, []byte("2")) @@ -19,7 +19,7 @@ func TestPrefixIteratorNoMatchNil(t *testing.T) { // Empty iterator for db populated after iterator created. func TestPrefixIteratorNoMatch1(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) itr := IteratePrefix(db, []byte("2")) @@ -32,7 +32,7 @@ func TestPrefixIteratorNoMatch1(t *testing.T) { // Empty iterator for prefix starting after db entry. func TestPrefixIteratorNoMatch2(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) db.SetSync(bz("3"), bz("value_3")) @@ -45,7 +45,7 @@ func TestPrefixIteratorNoMatch2(t *testing.T) { // Iterator with single val for db with single val, starting from that val. func TestPrefixIteratorMatch1(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) db.SetSync(bz("2"), bz("value_2")) @@ -63,7 +63,7 @@ func TestPrefixIteratorMatch1(t *testing.T) { // Iterator with prefix iterates over everything with same prefix. func TestPrefixIteratorMatches1N(t *testing.T) { - for backend, _ := range backends { + for backend := range backends { t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) { db := newTempDB(t, backend) diff --git a/events/events.go b/events/events.go index 3bc349306..f1b2a754e 100644 --- a/events/events.go +++ b/events/events.go @@ -6,7 +6,7 @@ package events import ( "sync" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) // Generic event data can be typed and registered with tendermint/go-amino @@ -27,7 +27,7 @@ type Fireable interface { } type EventSwitch interface { - Service + cmn.Service Fireable AddListenerForEvent(listenerID, event string, cb EventCallback) @@ -36,7 +36,7 @@ type EventSwitch interface { } type eventSwitch struct { - BaseService + cmn.BaseService mtx sync.RWMutex eventCells map[string]*eventCell @@ -45,7 +45,7 @@ type eventSwitch struct { func NewEventSwitch() EventSwitch { evsw := &eventSwitch{} - evsw.BaseService = *NewBaseService(nil, "EventSwitch", evsw) + evsw.BaseService = *cmn.NewBaseService(nil, "EventSwitch", evsw) return evsw } diff --git a/events/events_test.go b/events/events_test.go index 87db2a304..4995ae730 100644 --- a/events/events_test.go +++ b/events/events_test.go @@ -221,11 +221,11 @@ func TestRemoveListener(t *testing.T) { // add some listeners and make sure they work evsw.AddListenerForEvent("listener", "event1", func(data EventData) { - sum1 += 1 + sum1++ }) evsw.AddListenerForEvent("listener", "event2", func(data EventData) { - sum2 += 1 + sum2++ }) for i := 0; i < count; i++ { evsw.FireEvent("event1", true) diff --git a/merkle/simple_proof.go b/merkle/simple_proof.go index 83f89e598..7b8f82b46 100644 --- a/merkle/simple_proof.go +++ b/merkle/simple_proof.go @@ -67,13 +67,12 @@ func computeHashFromAunts(index int, total int, leafHash []byte, innerHashes [][ return nil } return SimpleHashFromTwoHashes(leftHash, innerHashes[len(innerHashes)-1]) - } else { - rightHash := computeHashFromAunts(index-numLeft, total-numLeft, leafHash, innerHashes[:len(innerHashes)-1]) - if rightHash == nil { - return nil - } - return SimpleHashFromTwoHashes(innerHashes[len(innerHashes)-1], rightHash) } + rightHash := computeHashFromAunts(index-numLeft, total-numLeft, leafHash, innerHashes[:len(innerHashes)-1]) + if rightHash == nil { + return nil + } + return SimpleHashFromTwoHashes(innerHashes[len(innerHashes)-1], rightHash) } } diff --git a/test/mutate.go b/test/mutate.go index 1dbe7a6bf..76534e8b1 100644 --- a/test/mutate.go +++ b/test/mutate.go @@ -1,7 +1,7 @@ package test import ( - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) // Contract: !bytes.Equal(input, output) && len(input) >= len(output) @@ -17,11 +17,11 @@ func MutateByteSlice(bytez []byte) []byte { bytez = mBytez // Try a random mutation - switch RandInt() % 2 { + switch cmn.RandInt() % 2 { case 0: // Mutate a single byte - bytez[RandInt()%len(bytez)] += byte(RandInt()%255 + 1) + bytez[cmn.RandInt()%len(bytez)] += byte(cmn.RandInt()%255 + 1) case 1: // Remove an arbitrary byte - pos := RandInt() % len(bytez) + pos := cmn.RandInt() % len(bytez) bytez = append(bytez[:pos], bytez[pos+1:]...) } return bytez