From cf49ba876fe8e7734acccd4c29289b77ea5829a5 Mon Sep 17 00:00:00 2001 From: Zach Ramsay Date: Tue, 3 Oct 2017 12:18:21 -0400 Subject: [PATCH] linter: couple fixes --- Makefile | 4 ++-- autofile/autofile_test.go | 21 ++++++++------------- common/os.go | 3 +-- common/service.go | 16 +++++++--------- merkle/simple_tree.go | 1 - 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 902197e77..25773ed36 100644 --- a/Makefile +++ b/Makefile @@ -31,9 +31,7 @@ metalinter_test: ensure_tools --enable=deadcode \ --enable=gas \ --enable=goconst \ - --enable=goimports \ --enable=gosimple \ - --enable=gotype \ --enable=ineffassign \ --enable=interfacer \ --enable=megacheck \ @@ -52,5 +50,7 @@ metalinter_test: ensure_tools #--enable=dupl \ #--enable=errcheck \ #--enable=gocyclo \ + #--enable=goimports \ #--enable=golint \ <== comments on anything exported + #--enable=gotype \ #--enable=unparam \ diff --git a/autofile/autofile_test.go b/autofile/autofile_test.go index c7aa93beb..05152219c 100644 --- a/autofile/autofile_test.go +++ b/autofile/autofile_test.go @@ -1,4 +1,3 @@ -// nolint: goimports package autofile import ( @@ -8,19 +7,18 @@ import ( "testing" "time" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" ) func TestSIGHUP(t *testing.T) { // First, create an AutoFile writing to a tempfile dir - file, name := Tempfile("sighup_test") - err := file.Close() - if err != nil { + file, name := cmn.Tempfile("sighup_test") + if err := file.Close(); err != nil { t.Fatalf("Error creating tempfile: %v", err) } // Here is the actual AutoFile - af, err := OpenAutoFile(name) + af, err := cmn.OpenAutoFile(name) if err != nil { t.Fatalf("Error creating autofile: %v", err) } @@ -36,8 +34,7 @@ func TestSIGHUP(t *testing.T) { } // Move the file over - err = os.Rename(name, name+"_old") - if err != nil { + if err := os.Rename(name, name+"_old"); err != nil { t.Fatalf("Error moving autofile: %v", err) } @@ -59,17 +56,15 @@ func TestSIGHUP(t *testing.T) { if err != nil { t.Fatalf("Error writing to autofile: %v", err) } - err = af.Close() - if err != nil { + if err := af.Close(); err != nil { t.Fatalf("Error closing autofile") } // Both files should exist - if body := MustReadFile(name + "_old"); string(body) != "Line 1\nLine 2\n" { + if body := cmn.MustReadFile(name + "_old"); string(body) != "Line 1\nLine 2\n" { t.Errorf("Unexpected body %s", body) } - if body := MustReadFile(name); string(body) != "Line 3\nLine 4\n" { + if body := cmn.MustReadFile(name); string(body) != "Line 3\nLine 4\n" { t.Errorf("Unexpected body %s", body) } - } diff --git a/common/os.go b/common/os.go index 8b7143f5a..19aa479f9 100644 --- a/common/os.go +++ b/common/os.go @@ -8,7 +8,6 @@ import ( "os" "os/signal" "strings" - "syscall" ) var ( @@ -18,7 +17,7 @@ var ( func TrapSignal(cb func()) { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) - signal.Notify(c, syscall.SIGTERM) + signal.Notify(c, os.Kill) // nolint: megacheck go func() { for sig := range c { fmt.Printf("captured %v, exiting...\n", sig) diff --git a/common/service.go b/common/service.go index 5ac386316..2d86baafe 100644 --- a/common/service.go +++ b/common/service.go @@ -140,18 +140,16 @@ func (bs *BaseService) OnStop() {} // Implements Service func (bs *BaseService) Reset() (bool, error) { - if atomic.CompareAndSwapUint32(&bs.stopped, 1, 0) { - // whether or not we've started, we can reset - atomic.CompareAndSwapUint32(&bs.started, 1, 0) - - bs.Quit = make(chan struct{}) - return true, bs.impl.OnReset() - } else { + if stopped := atomic.CompareAndSwapUint32(&bs.stopped, 1, 0); !stopped { bs.Logger.Debug(Fmt("Can't reset %v. Not stopped", bs.name), "impl", bs.impl) return false, nil } - // never happens - return false, nil // nolint: vet + + // whether or not we've started, we can reset + atomic.CompareAndSwapUint32(&bs.started, 1, 0) + + bs.Quit = make(chan struct{}) + return true, bs.impl.OnReset() } // Implements Service diff --git a/merkle/simple_tree.go b/merkle/simple_tree.go index b373743fc..8106246d6 100644 --- a/merkle/simple_tree.go +++ b/merkle/simple_tree.go @@ -22,7 +22,6 @@ For larger datasets, use IAVLTree. */ -// nolint: goimports package merkle import (