From f8b65d53ba50128bb12a8fc2ce82503de0d18540 Mon Sep 17 00:00:00 2001 From: Cenk Alti Date: Sat, 27 Aug 2022 13:33:20 -0400 Subject: [PATCH] Add revive to the list of linters. Part of "Enhance the static-analysis workflow" issue. #14164 Signed-off-by: Cenk Alti --- .golangci.yaml | 1 + contrib/raftexample/httpapi.go | 12 +++++----- contrib/raftexample/main.go | 2 +- tools/benchmark/cmd/util.go | 8 +++---- tools/etcd-dump-logs/etcd-dump-log_test.go | 8 +++---- tools/etcd-dump-logs/main.go | 28 +++++++++++----------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index fb3c4cb2d..8c92fbba7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -25,6 +25,7 @@ linters: - staticcheck - stylecheck - unused + - revive linters-settings: # please keep this alphabetized staticcheck: diff --git a/contrib/raftexample/httpapi.go b/contrib/raftexample/httpapi.go index 70e2cef4f..b85e6a213 100644 --- a/contrib/raftexample/httpapi.go +++ b/contrib/raftexample/httpapi.go @@ -60,7 +60,7 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - nodeId, err := strconv.ParseUint(key[1:], 0, 64) + nodeID, err := strconv.ParseUint(key[1:], 0, 64) if err != nil { log.Printf("Failed to convert ID for conf change (%v)\n", err) http.Error(w, "Failed on POST", http.StatusBadRequest) @@ -69,14 +69,14 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) { cc := raftpb.ConfChange{ Type: raftpb.ConfChangeAddNode, - NodeID: nodeId, + NodeID: nodeID, Context: url, } h.confChangeC <- cc // As above, optimistic that raft will apply the conf change w.WriteHeader(http.StatusNoContent) case http.MethodDelete: - nodeId, err := strconv.ParseUint(key[1:], 0, 64) + nodeID, err := strconv.ParseUint(key[1:], 0, 64) if err != nil { log.Printf("Failed to convert ID for conf change (%v)\n", err) http.Error(w, "Failed on DELETE", http.StatusBadRequest) @@ -85,7 +85,7 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) { cc := raftpb.ConfChange{ Type: raftpb.ConfChangeRemoveNode, - NodeID: nodeId, + NodeID: nodeID, } h.confChangeC <- cc @@ -100,8 +100,8 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -// serveHttpKVAPI starts a key-value server with a GET/PUT API and listens. -func serveHttpKVAPI(kv *kvstore, port int, confChangeC chan<- raftpb.ConfChange, errorC <-chan error) { +// serveHTTPKVAPI starts a key-value server with a GET/PUT API and listens. +func serveHTTPKVAPI(kv *kvstore, port int, confChangeC chan<- raftpb.ConfChange, errorC <-chan error) { srv := http.Server{ Addr: ":" + strconv.Itoa(port), Handler: &httpKVAPI{ diff --git a/contrib/raftexample/main.go b/contrib/raftexample/main.go index b52a1fb64..1845d0964 100644 --- a/contrib/raftexample/main.go +++ b/contrib/raftexample/main.go @@ -41,5 +41,5 @@ func main() { kvs = newKVStore(<-snapshotterReady, proposeC, commitC, errorC) // the key-value http handler will propose updates to raft - serveHttpKVAPI(kvs, *kvport, confChangeC, errorC) + serveHTTPKVAPI(kvs, *kvport, confChangeC, errorC) } diff --git a/tools/benchmark/cmd/util.go b/tools/benchmark/cmd/util.go index f8c98246e..ab644b3d4 100644 --- a/tools/benchmark/cmd/util.go +++ b/tools/benchmark/cmd/util.go @@ -22,7 +22,7 @@ import ( "strings" "github.com/bgentry/speakeasy" - "go.etcd.io/etcd/client/v3" + clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/pkg/v3/report" "google.golang.org/grpc/grpclog" ) @@ -47,16 +47,16 @@ func mustFindLeaderEndpoints(c *clientv3.Client) { os.Exit(1) } - leaderId := uint64(0) + leaderID := uint64(0) for _, ep := range c.Endpoints() { if sresp, serr := c.Status(context.TODO(), ep); serr == nil { - leaderId = sresp.Leader + leaderID = sresp.Leader break } } for _, m := range resp.Members { - if m.ID == leaderId { + if m.ID == leaderID { leaderEps = m.ClientURLs return } diff --git a/tools/etcd-dump-logs/etcd-dump-log_test.go b/tools/etcd-dump-logs/etcd-dump-log_test.go index ca7f5c325..4f2090122 100644 --- a/tools/etcd-dump-logs/etcd-dump-log_test.go +++ b/tools/etcd-dump-logs/etcd-dump-log_test.go @@ -44,8 +44,8 @@ func TestEtcdDumpLogEntryType(t *testing.T) { t.Skipf("%q does not exist", dumpLogsBinary) } - decoder_correctoutputformat := filepath.Join(binDir, "/testdecoder/decoder_correctoutputformat.sh") - decoder_wrongoutputformat := filepath.Join(binDir, "/testdecoder/decoder_wrongoutputformat.sh") + decoderCorrectOutputFormat := filepath.Join(binDir, "/testdecoder/decoder_correctoutputformat.sh") + decoderWrongOutputFormat := filepath.Join(binDir, "/testdecoder/decoder_wrongoutputformat.sh") p := t.TempDir() @@ -100,8 +100,8 @@ func TestEtcdDumpLogEntryType(t *testing.T) { {"lease grant entry-type", []string{"-entry-type", "IRRLeaseGrant", p}, "expectedoutput/listIRRLeaseGrant.output"}, {"lease revoke entry-type", []string{"-entry-type", "IRRLeaseRevoke", p}, "expectedoutput/listIRRLeaseRevoke.output"}, {"confchange and txn entry-type", []string{"-entry-type", "ConfigChange,IRRCompaction", p}, "expectedoutput/listConfigChangeIRRCompaction.output"}, - {"decoder_correctoutputformat", []string{"-stream-decoder", decoder_correctoutputformat, p}, "expectedoutput/decoder_correctoutputformat.output"}, - {"decoder_wrongoutputformat", []string{"-stream-decoder", decoder_wrongoutputformat, p}, "expectedoutput/decoder_wrongoutputformat.output"}, + {"decoder_correctoutputformat", []string{"-stream-decoder", decoderCorrectOutputFormat, p}, "expectedoutput/decoder_correctoutputformat.output"}, + {"decoder_wrongoutputformat", []string{"-stream-decoder", decoderWrongOutputFormat, p}, "expectedoutput/decoder_wrongoutputformat.output"}, } for _, argtest := range argtests { diff --git a/tools/etcd-dump-logs/main.go b/tools/etcd-dump-logs/main.go index 82789c810..c887d76ea 100644 --- a/tools/etcd-dump-logs/main.go +++ b/tools/etcd-dump-logs/main.go @@ -90,12 +90,12 @@ and output a hex encoded line of binary for each input line`) case nil: walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term nodes := genIDSlice(snapshot.Metadata.ConfState.Voters) - confstateJson, err := json.Marshal(snapshot.Metadata.ConfState) + confStateJSON, err := json.Marshal(snapshot.Metadata.ConfState) if err != nil { - confstateJson = []byte(fmt.Sprintf("confstate err: %v", err)) + confStateJSON = []byte(fmt.Sprintf("confstate err: %v", err)) } fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s confstate=%s\n", - walsnap.Term, walsnap.Index, nodes, confstateJson) + walsnap.Term, walsnap.Index, nodes, confStateJSON) case snap.ErrNoSnapshot: fmt.Printf("Snapshot:\nempty\n") default: @@ -372,9 +372,9 @@ func listEntriesType(entrytype string, streamdecoder string, ents []raftpb.Entry return } - decoder_status, decoded_data := parseDecoderOutput(decoderoutput) + decoderStatus, decodedData := parseDecoderOutput(decoderoutput) - fmt.Printf("\t%s\t%s", decoder_status, decoded_data) + fmt.Printf("\t%s\t%s", decoderStatus, decodedData) } } @@ -393,19 +393,19 @@ func listEntriesType(entrytype string, streamdecoder string, ents []raftpb.Entry } func parseDecoderOutput(decoderoutput string) (string, string) { - var decoder_status string - var decoded_data string + var decoderStatus string + var decodedData string output := strings.Split(decoderoutput, "|") switch len(output) { case 1: - decoder_status = "decoder output format is not right, print output anyway" - decoded_data = decoderoutput + decoderStatus = "decoder output format is not right, print output anyway" + decodedData = decoderoutput case 2: - decoder_status = output[0] - decoded_data = output[1] + decoderStatus = output[0] + decodedData = output[1] default: - decoder_status = output[0] + "(*WARNING: data might contain deliminator used by etcd-dump-logs)" - decoded_data = strings.Join(output[1:], "") + decoderStatus = output[0] + "(*WARNING: data might contain deliminator used by etcd-dump-logs)" + decodedData = strings.Join(output[1:], "") } - return decoder_status, decoded_data + return decoderStatus, decodedData }