Skip to content

Commit

Permalink
add golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Aug 28, 2019
1 parent 1ca4a4a commit e5a1d5d
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 65 deletions.
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters-settings:
gocritic:
disabled-checks:
- ifElseChain
- elseif

linters:
enable:
- gofmt
- gocritic
- unconvert
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: go

before_install:
- go get golang.org/x/lint/golint

script:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
- golangci-lint run
- go vet ./...
- golint ./...
- go test ./...

go:
- 1.10.x
- 1.11.x
- 1.12.x
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ go-merkle-tree

Go language to build and check keybase's sitewide merkle tree.

[![Travis CI](https://travis-ci.org/keybase/go-merkle-tree.svg?branch=master)](https://travis-ci.org/keybase/go-merkle-tree)

[![GoDoc](https://godoc.org/github.com/keybase/go-merkle-tree?status.svg)](https://godoc.org/github.com/keybase/go-merkle-tree)
6 changes: 1 addition & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewConfig(h Hasher, m ChildIndex, n ChildIndex, v ValueConstructor) Config

func (c Config) prefixAndIndexAtLevel(level Level, h Hash) (Prefix, ChildIndex) {
prfx, ci := bitslice(h, int(c.c), int(level))
return Prefix(prfx), ChildIndex(ci)
return prfx, ChildIndex(ci)
}
func (c Config) prefixAtLevel(level Level, h Hash) Prefix {
ret, _ := c.prefixAndIndexAtLevel(level, h)
Expand All @@ -70,10 +70,6 @@ func (c Config) PrefixAtLevel(level Level, h Hash) Prefix {
return c.prefixAtLevel(level, h)
}

func div8roundUp(i ChildIndex) ChildIndex {
return ((i + 7) >> 3)
}

func (c Config) formatPrefix(index ChildIndex) Prefix {
ret := make([]byte, 4)
binary.BigEndian.PutUint32(ret, uint32(index))
Expand Down
20 changes: 9 additions & 11 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@ func ExampleTree_Build() {
factory := merkleTree.NewTestObjFactory()

// Make a whole bunch of phony objects in our Object Factory.
var objs []merkleTree.KeyValuePair
objs = factory.Mproduce(1024)
objs := factory.Mproduce(1024)

// Collect and sort the objects into a "sorted map"
var sm *merkleTree.SortedMap
sm = merkleTree.NewSortedMapFromList(objs)
sm := merkleTree.NewSortedMapFromList(objs)

// Make a test storage engine
var eng merkleTree.StorageEngine
eng = merkleTree.NewMemEngine()
eng := merkleTree.NewMemEngine()

// 256 children per node; once there are 512 entries in a leaf,
// then split the leaf by adding more parents.
var config merkleTree.Config
config = merkleTree.NewConfig(merkleTree.SHA512Hasher{}, 256, 512, factory)
config := merkleTree.NewConfig(merkleTree.SHA512Hasher{}, 256, 512, factory)

// Make a new tree object with this engine and these config
// values
var tree *merkleTree.Tree
tree = merkleTree.NewTree(eng, config)
tree := merkleTree.NewTree(eng, config)

// Make an empty Tranaction info for now
var txInfo merkleTree.TxInfo

// Build the tree
tree.Build(context.TODO(), sm, txInfo)
err := tree.Build(context.TODO(), sm, txInfo)
if err != nil {
panic(err.Error())
}
}
2 changes: 0 additions & 2 deletions inode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package merkleTree

import ()

type childPointerMap struct {
tab []Hash
}
Expand Down
6 changes: 0 additions & 6 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package merkleTree

import (
"encoding/hex"
"encoding/json"
)

func (n *Node) findChildByIndex(i ChildIndex) (Hash, error) {
Expand All @@ -23,11 +22,6 @@ func (n Node) export(h Hasher, prevRoot Hash, level Level) (hash Hash, node Node
return hash, n, objExported, err
}

func dump(i interface{}) string {
ret, _ := json.MarshalIndent(i, "", " ")
return string(ret)
}

// MarshalJSON prints out a hash for debugging purposes. Not recommended for actual
// JSONing
func (h Hash) MarshalJSON() ([]byte, error) {
Expand Down
32 changes: 2 additions & 30 deletions obj_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ package merkleTree
import (
"crypto/rand"
"encoding/hex"
"fmt"
)

func genString(l int) string {
return hex.EncodeToString(genBinary((l + 2) / 1))[0:l]
}

func genBinary(l int) []byte {
b := make([]byte, l)
rand.Read(b)
_, _ = rand.Read(b)
return b
}

type testValue struct {
_struct bool `codec:",toarray"`
_struct bool `codec:",toarray"` //nolint
Seqno int
Key string
KeyRaw []byte
Expand All @@ -36,14 +31,6 @@ func NewTestObjFactory() *TestObjFactory {
}
}

func (of TestObjFactory) dumpAll() []KeyValuePair {
var ret []KeyValuePair
for _, v := range of.objs {
ret = append(ret, v)
}
return ret
}

// Produce one test object
func (of *TestObjFactory) Produce() KeyValuePair {
key := genBinary(8)
Expand All @@ -64,21 +51,6 @@ func (of *TestObjFactory) Mproduce(n int) []KeyValuePair {
return ret
}

func (of *TestObjFactory) modifySome(mod int) {
i := 0
for _, v := range of.objs {
tv, ok := v.Value.(testValue)
if !ok {
panic(fmt.Sprintf("Got value of wrong type: %T", v))
}
if (i % mod) == 0 {
tv.Seqno *= 2
tv.Key += "-yo-dawg"
}
i++
}
}

func (of *TestObjFactory) Construct() interface{} {
return testValue{}
}
4 changes: 0 additions & 4 deletions sorted_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func (s *SortedMap) sort() {
sort.Sort(byKey(s.list))
}

func (s *SortedMap) push(kp KeyValuePair) {
s.list = append(s.list, kp)
}

func (s *SortedMap) exportToNode(h Hasher, prevRoot Hash, level Level) (hash Hash, node Node, objExported []byte, err error) {
node.Type = NodeTypeLeaf
node.Leafs = s.list
Expand Down
6 changes: 0 additions & 6 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@ func (t *Tree) Find(ctx context.Context, h Hash) (ret interface{}, root Hash, er
return t.findTyped(ctx, h, false)
}

// findUnsafe shouldn't be used, since it will skip hash comparisons
// at interior nodes. It's mainly here for testing.
func (t *Tree) findUnsafe(ctx context.Context, h Hash) (ret interface{}, root Hash, err error) {
return t.findTyped(ctx, h, true)
}

type step struct {
p Prefix
i ChildIndex
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Prefix []byte
// Note that though the key is of type `Hash`, it can be a smaller or different
// hash from the one used for interior nodes.
type KeyValuePair struct {
_struct bool `codec:",toarray"`
_struct bool `codec:",toarray"` //nolint
Key Hash `codec:"k"`
Value interface{} `codec:"v"`
}
Expand Down

0 comments on commit e5a1d5d

Please sign in to comment.