From a962a0c5262e581e517ab6eaeb1c850025e0af0a Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 17 Jul 2018 16:33:47 -0500 Subject: [PATCH] Fix linter issues: deadcode --- .travis.yml | 6 ++---- Makefile | 27 ++++++++++++++++++++++++--- attr.go | 6 ------ cluster.go | 3 --- cluster_internal_test.go | 3 ++- executor.go | 9 --------- fragment_internal_test.go | 4 +++- http/handler.go | 13 +------------ roaring/roaring.go | 36 ++---------------------------------- view_internal_test.go | 4 +++- 10 files changed, 37 insertions(+), 74 deletions(-) diff --git a/.travis.yml b/.travis.yml index 382a3d65a..6c77fe0fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,10 +21,8 @@ jobs: include: - stage: metalinter install: - - make -B install-dep vendor - - go get -u github.com/alecthomas/gometalinter - - gometalinter --install - script: make metalinter + - make -B install-dep vendor install-gometalinter + script: make gometalinter env: - GOARCH=amd64 - stage: deploy diff --git a/Makefile b/Makefile index 7a1ed5db7..65df8f894 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build check-clean clean cover cover-viz default docker docker-build docker-test generate generate-protoc generate-pql install install-build-deps install-dep install-protoc install-protoc-gen-gofast install-peg metalinter prerelease prerelease-upload release release-build require-dep require-protoc require-protoc-gen-gofast require-peg test +.PHONY: build check-clean clean cover cover-viz default docker docker-build docker-test generate generate-protoc generate-pql gometalinter install install-build-deps install-dep install-gometalinter install-protoc install-protoc-gen-gofast install-peg prerelease prerelease-upload release release-build require-dep require-gometalinter require-protoc require-protoc-gen-gofast require-peg test CLONE_URL=github.com/pilosa/pilosa VERSION := $(shell git describe --tags 2> /dev/null || echo unknown) @@ -108,8 +108,21 @@ docker-build: docker-test: docker run --rm -v $(PWD):/go/src/$(CLONE_URL) -w /go/src/$(CLONE_URL) golang:$(GO_VERSION) go test -tags='$(BUILD_TAGS)' $(TESTFLAGS) ./... -metalinter: - gometalinter --vendor --disable-all --enable=gotype --enable=gotypex --enable=gofmt --enable=goimports --enable=interfacer --enable=misspell --enable=unparam --deadline=60s --exclude "^internal/.*\.pb\.go" ./... +# Run gometalinter with custom flags +gometalinter: require-gometalinter + gometalinter --vendor --disable-all \ + --deadline=60s \ + --enable=deadcode \ + --enable=gofmt \ + --enable=goimports \ + --enable=gotype \ + --enable=gotypex \ + --enable=interfacer \ + --enable=misspell \ + --enable=unparam \ + --exclude "^internal/.*\.pb\.go" \ + --exclude "^pql/pql.peg.go" \ + ./... ###################### # Build dependencies # @@ -134,6 +147,9 @@ require-protoc: require-peg: $(call require,peg) +require-gometalinter: + $(call require,gometalinter) + install-build-deps: install-dep install-protoc-gen-gofast install-protoc install-stringer install-peg install-dep: @@ -150,3 +166,8 @@ install-protoc: install-peg: go get github.com/pointlander/peg + +install-gometalinter: + go get -u github.com/alecthomas/gometalinter + gometalinter --install + go get github.com/remyoudompheng/go-misc/deadcode diff --git a/attr.go b/attr.go index b6096a994..629cbf587 100644 --- a/attr.go +++ b/attr.go @@ -204,12 +204,6 @@ func DecodeAttrs(v []byte) (map[string]interface{}, error) { return decodeAttrs(pb.GetAttrs()), nil } -func newMemAttrStore() AttrStore { - return &memAttrStore{ - store: make(map[uint64]map[string]interface{}), - } -} - // memAttrStore represents an in-memory implementation of the AttrStore interface. type memAttrStore struct { store map[uint64]map[string]interface{} diff --git a/cluster.go b/cluster.go index 6699a5e56..01f80c029 100644 --- a/cluster.go +++ b/cluster.go @@ -792,9 +792,6 @@ type Hasher interface { Hash(key uint64, n int) int } -// newHasher returns a new instance of the default hasher. -func newHasher() Hasher { return &jmphasher{} } - // jmphasher represents an implementation of jmphash. Implements Hasher. type jmphasher struct{} diff --git a/cluster_internal_test.go b/cluster_internal_test.go index 58b40ccbf..07a6521d4 100644 --- a/cluster_internal_test.go +++ b/cluster_internal_test.go @@ -372,7 +372,8 @@ func TestHasher(t *testing.T) { {0x0ddc0ffeebadf00d, []int{0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 15, 15, 15, 15}}, } { for i, v := range tt.bucket { - if got := newHasher().Hash(tt.key, i+1); got != v { + hasher := &jmphasher{} + if got := hasher.Hash(tt.key, i+1); got != v { t.Errorf("hash(%v,%v)=%v, want %v", tt.key, i+1, got, v) } } diff --git a/executor.go b/executor.go index d0af5b241..52f851e5a 100644 --- a/executor.go +++ b/executor.go @@ -1672,15 +1672,6 @@ type execOptions struct { ExcludeColumns bool } -// decodeError returns an error representation of s if s is non-blank. -// Returns nil if s is blank. -func decodeError(s string) error { - if s == "" { - return nil - } - return errors.New(s) -} - // hasOnlySetRowAttrs returns true if calls only contains SetRowAttrs() calls. func hasOnlySetRowAttrs(calls []*pql.Call) bool { if len(calls) == 0 { diff --git a/fragment_internal_test.go b/fragment_internal_test.go index 0d4e9fa49..a04ea5387 100644 --- a/fragment_internal_test.go +++ b/fragment_internal_test.go @@ -1250,7 +1250,9 @@ func mustOpenFragment(index, field, view string, shard uint64, cacheType string) f := newFragment(file.Name(), index, field, view, shard) f.CacheType = cacheType - f.RowAttrStore = newMemAttrStore() + f.RowAttrStore = &memAttrStore{ + store: make(map[uint64]map[string]interface{}), + } if err := f.Open(); err != nil { panic(err) diff --git a/http/handler.go b/http/handler.go index a69d9990c..7a3d611ac 100644 --- a/http/handler.go +++ b/http/handler.go @@ -1122,12 +1122,9 @@ func (h *Handler) handleGetVersion(w http.ResponseWriter, r *http.Request) { // QueryResult types. const ( - queryResultTypeNil uint32 = iota - QueryResultTypeRow + QueryResultTypeRow uint32 = iota QueryResultTypePairs - queryResultTypeValCount QueryResultTypeUint64 - queryResultTypeBool ) // parseUint64Slice returns a slice of uint64s from a comma-delimited string. @@ -1149,14 +1146,6 @@ func parseUint64Slice(s string) ([]uint64, error) { return a, nil } -// errorString returns the string representation of err. -func errorString(err error) string { - if err == nil { - return "" - } - return err.Error() -} - func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r *http.Request) { if !validHeaderAcceptJSON(r.Header) { http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable) diff --git a/roaring/roaring.go b/roaring/roaring.go index 3a0418aa3..7c2a4e11b 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -1800,7 +1800,7 @@ type containerInfo struct { // flip returns a new container containing the inverse of all // bits in a. -func flip(a *Container) *Container { +func flip(a *Container) *Container { // nolint: deadcode if a.isArray() { return flipArray(a) } else if a.isRun() { @@ -3304,7 +3304,7 @@ func xorBitmapRun(a, b *Container) *Container { return output } -func bitmapsEqual(b, c *Bitmap) error { +func bitmapsEqual(b, c *Bitmap) error { // nolint: deadcode if b.OpWriter != c.OpWriter { return errors.New("opWriters not equal") } @@ -3336,22 +3336,6 @@ func popcount(x uint64) uint64 { return uint64(bits.OnesCount64(x)) } -func popcountSlice(s []uint64) uint64 { - cnt := uint64(0) - for _, x := range s { - cnt += popcount(x) - } - return cnt -} - -func popcountMaskSlice(s, m []uint64) uint64 { - cnt := uint64(0) - for i := range s { - cnt += popcount(s[i] &^ m[i]) - } - return cnt -} - func popcountAndSlice(s, m []uint64) uint64 { cnt := uint64(0) for i := range s { @@ -3359,19 +3343,3 @@ func popcountAndSlice(s, m []uint64) uint64 { } return cnt } - -func popcountOrSlice(s, m []uint64) uint64 { - cnt := uint64(0) - for i := range s { - cnt += popcount(s[i] | m[i]) - } - return cnt -} - -func popcountXorSlice(s, m []uint64) uint64 { - cnt := uint64(0) - for i := range s { - cnt += popcount(s[i] ^ m[i]) - } - return cnt -} diff --git a/view_internal_test.go b/view_internal_test.go index 6fe0b0e33..3f00fb38a 100644 --- a/view_internal_test.go +++ b/view_internal_test.go @@ -30,7 +30,9 @@ func mustOpenView(index, field, name string) *view { if err := v.open(); err != nil { panic(err) } - v.rowAttrStore = newMemAttrStore() + v.rowAttrStore = &memAttrStore{ + store: make(map[uint64]map[string]interface{}), + } return v }