From 990780bd935bcd32362e34493282cee071b289ae Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 20 Jul 2018 11:19:24 -0500 Subject: [PATCH] Fix linter issues: staticcheck (covered by megacheck, along with gosimple and unused) --- Makefile | 3 +-- attr_test.go | 11 +++++++++-- http/client_test.go | 4 ++-- lru/lru.go | 4 ++-- pql/pqlpeg_test.go | 2 +- server/config_test.go | 3 +++ 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index d0013ae02..10fd62e0c 100644 --- a/Makefile +++ b/Makefile @@ -116,16 +116,15 @@ gometalinter: require-gometalinter --enable=gochecknoinits \ --enable=gofmt \ --enable=goimports \ - --enable=gosimple \ --enable=gotype \ --enable=gotypex \ --enable=ineffassign \ --enable=interfacer \ --enable=maligned \ + --enable=megacheck \ --enable=misspell \ --enable=nakedret \ --enable=unparam \ - --enable=unused \ --enable=vet \ --exclude "^internal/.*\.pb\.go" \ --exclude "^pql/pql.peg.go" \ diff --git a/attr_test.go b/attr_test.go index 0c848e2ff..3d76c4d63 100644 --- a/attr_test.go +++ b/attr_test.go @@ -164,18 +164,25 @@ func BenchmarkAttrStore_Duplicate(b *testing.B) { // Update attributes with an existing subset. cpuN := runtime.GOMAXPROCS(0) var wg sync.WaitGroup + errchan := make(chan error) for i := 0; i < cpuN; i++ { wg.Add(1) go func() { defer wg.Done() for j := 0; j < b.N/cpuN; j++ { if err := s.SetAttrs(uint64(j%n), map[string]interface{}{"A": int64(100), "B": "foo", "D": 100.2}); err != nil { - b.Fatal(err) + errchan <- err } } }() } - wg.Wait() + go func() { + wg.Wait() + close(errchan) + }() + if err := <-errchan; err != nil { + b.Fatal(err) + } } // MustOpenAttrStore returns a new, opened attribute store at a temporary path. Panic on error. diff --git a/http/client_test.go b/http/client_test.go index 0101bd2a6..0d60b443e 100644 --- a/http/client_test.go +++ b/http/client_test.go @@ -128,12 +128,12 @@ func TestClient_MultiNode(t *testing.T) { Remote: false, } - result, err := client[0].Query(context.Background(), "i", queryRequest) + _, err = client[0].Query(context.Background(), "i", queryRequest) if err != nil { t.Fatal(err) } - result, err = client[0].Query(context.Background(), "i", queryRequest) + result, err := client[0].Query(context.Background(), "i", queryRequest) if err != nil { t.Fatal(err) } diff --git a/lru/lru.go b/lru/lru.go index 8ab4b9cd9..d7bb1929c 100644 --- a/lru/lru.go +++ b/lru/lru.go @@ -83,7 +83,7 @@ func (c *Cache) Get(key Key) (value interface{}, ok bool) { } // remove removes the provided key from the cache. -func (c *Cache) remove(key Key) { // nolint: unused +func (c *Cache) remove(key Key) { // nolint: megacheck if c.cache == nil { return } @@ -121,7 +121,7 @@ func (c *Cache) Len() int { } // clear purges all stored items from the cache. -func (c *Cache) clear() { // nolint: unused +func (c *Cache) clear() { // nolint: megacheck if c.OnEvicted != nil { for _, e := range c.cache { kv := e.Value.(*entry) diff --git a/pql/pqlpeg_test.go b/pql/pqlpeg_test.go index 076261599..2911224eb 100644 --- a/pql/pqlpeg_test.go +++ b/pql/pqlpeg_test.go @@ -31,7 +31,7 @@ SetBit(Union(Zitmap(row==4), Intersect(Qitmap(blah>4), Ritmap(field="http://zoo9 t.Fatalf("Failed, got: %s", q) } - q, err = ParseString("C(a=falsen0)") + _, err = ParseString("C(a=falsen0)") if err != nil { t.Fatalf("falsen0 should have been parsed as a string") } diff --git a/server/config_test.go b/server/config_test.go index 2027ef35a..78b66b5d5 100644 --- a/server/config_test.go +++ b/server/config_test.go @@ -54,6 +54,9 @@ func TestDuration(t *testing.T) { } err = d.UnmarshalText([]byte("3m2s")) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } v, _ = d.MarshalText() if !reflect.DeepEqual(b, v) { t.Fatalf("Unexpected marshalled value %v", v)