gometalinter -> golangci-lint migration (#3933)

{,scripts/}Makefile:
- Remove gometalinter, install golangci-lint.
- Remove distinction between tools and devtools.
  Just tools is enough.
- test_lint -> lint
  Migrating away from underscore separated names.
- Remove unnecessary targets.
- Drop tendermint/lint. Incompatbile with golangci-lint
  and no longer necessary anyway.
- Fix misleading message in go-mod-cache.
- New ci-target to avoid download tools twice.
- Run tests with -mod=readonly.

Port tools/gometalinter.json to .golangci.yml
Update CircleCI config accordingly.

Closes: #3896
This commit is contained in:
Alessio Treglia
2019-03-19 17:52:43 +01:00
committed by GitHub
parent faefc80769
commit cdf2b7a7c5
24 changed files with 213 additions and 131 deletions
+24
View File
@@ -11,6 +11,17 @@ type AddNewKey struct {
Index int `json:"index,string,omitempty"`
}
// NewAddNewKey constructs a new AddNewKey request structure.
func NewAddNewKey(name, password, mnemonic string, account, index int) AddNewKey {
return AddNewKey{
Name: name,
Password: password,
Mnemonic: mnemonic,
Account: account,
Index: index,
}
}
// RecoverKeyBody recovers a key
type RecoverKey struct {
Password string `json:"password"`
@@ -19,13 +30,26 @@ type RecoverKey struct {
Index int `json:"index,string,omitempty"`
}
// NewRecoverKey constructs a new RecoverKey request structure.
func NewRecoverKey(password, mnemonic string, account, index int) RecoverKey {
return RecoverKey{Password: password, Mnemonic: mnemonic, Account: account, Index: index}
}
// UpdateKeyReq requests updating a key
type UpdateKeyReq struct {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
}
// NewUpdateKeyReq constructs a new UpdateKeyReq structure.
func NewUpdateKeyReq(old, new string) UpdateKeyReq {
return UpdateKeyReq{OldPassword: old, NewPassword: new}
}
// DeleteKeyReq requests deleting a key
type DeleteKeyReq struct {
Password string `json:"password"`
}
// NewDeleteKeyReq constructs a new DeleteKeyReq structure.
func NewDeleteKeyReq(password string) DeleteKeyReq { return DeleteKeyReq{Password: password} }
+3 -1
View File
@@ -145,7 +145,9 @@ func fingerprintForCertificate(certBytes []byte) (string, error) {
return "", err
}
h := sha256.New()
h.Write(cert.Raw)
if _, err := h.Write(cert.Raw); err != nil {
return "", err
}
fingerprintBytes := h.Sum(nil)
var buf bytes.Buffer
for i, b := range fingerprintBytes {
+7 -7
View File
@@ -227,7 +227,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
genDoc, err := tmtypes.GenesisDocFromFile(genesisFile)
require.Nil(t, err)
genDoc.Validators = nil
genDoc.SaveAs(genesisFile)
require.NoError(t, genDoc.SaveAs(genesisFile))
genTxs := []json.RawMessage{}
// append any additional (non-proposing) validators
@@ -337,7 +337,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
cleanup = func() {
logger.Debug("cleaning up LCD initialization")
node.Stop()
node.Stop() //nolint:errcheck
node.Wait()
lcd.Close()
}
@@ -394,7 +394,7 @@ func startLCD(logger log.Logger, listenAddr string, cdc *codec.Codec, t *testing
if err != nil {
return nil, err
}
go tmrpc.StartHTTPServer(listener, rs.Mux, logger)
go tmrpc.StartHTTPServer(listener, rs.Mux, logger) //nolint:errcheck
return listener, nil
}
@@ -559,7 +559,7 @@ func getKeys(t *testing.T, port string) []keys.KeyOutput {
// POST /keys Create a new account locally
func doKeysPost(t *testing.T, port, name, password, mnemonic string, account int, index int) keys.KeyOutput {
pk := clientkeys.AddNewKey{name, password, mnemonic, account, index}
pk := clientkeys.NewAddNewKey(name, password, mnemonic, account, index)
req, err := cdc.MarshalJSON(pk)
require.NoError(t, err)
@@ -585,7 +585,7 @@ func getKeysSeed(t *testing.T, port string) string {
// POST /keys/{name}/recove Recover a account from a seed
func doRecoverKey(t *testing.T, port, recoverName, recoverPassword, mnemonic string, account uint32, index uint32) {
pk := clientkeys.RecoverKey{recoverPassword, mnemonic, int(account), int(index)}
pk := clientkeys.NewRecoverKey(recoverPassword, mnemonic, int(account), int(index))
req, err := cdc.MarshalJSON(pk)
require.NoError(t, err)
@@ -613,7 +613,7 @@ func getKey(t *testing.T, port, name string) keys.KeyOutput {
// PUT /keys/{name} Update the password for this account in the KMS
func updateKey(t *testing.T, port, name, oldPassword, newPassword string, fail bool) {
kr := clientkeys.UpdateKeyReq{oldPassword, newPassword}
kr := clientkeys.NewUpdateKeyReq(oldPassword, newPassword)
req, err := cdc.MarshalJSON(kr)
require.NoError(t, err)
keyEndpoint := fmt.Sprintf("/keys/%s", name)
@@ -627,7 +627,7 @@ func updateKey(t *testing.T, port, name, oldPassword, newPassword string, fail b
// DELETE /keys/{name} Remove an account
func deleteKey(t *testing.T, port, name, password string) {
dk := clientkeys.DeleteKeyReq{password}
dk := clientkeys.NewDeleteKeyReq(password)
req, err := cdc.MarshalJSON(dk)
require.NoError(t, err)
keyEndpoint := fmt.Sprintf("/keys/%s", name)
+4 -1
View File
@@ -1,6 +1,7 @@
package rest
import (
"log"
"net/http"
"github.com/cosmos/cosmos-sdk/client"
@@ -67,6 +68,8 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
}
w.Header().Set("Content-Type", "application/json")
w.Write(output)
if _, err := w.Write(output); err != nil {
log.Printf("could not write response: %v", err)
}
return
}
+7 -10
View File
@@ -115,20 +115,19 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
vars := mux.Vars(r)
height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("ERROR: Couldn't parse block height. Assumed format is '/block/{height}'."))
rest.WriteErrorResponse(w, http.StatusBadRequest,
"ERROR: Couldn't parse block height. Assumed format is '/block/{height}'.")
return
}
chainHeight, err := GetChainHeight(cliCtx)
if height > chainHeight {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
rest.WriteErrorResponse(w, http.StatusNotFound,
"ERROR: Requested block height is bigger then the chain length.")
return
}
output, err := getBlock(cliCtx, &height)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
@@ -140,14 +139,12 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
height, err := GetChainHeight(cliCtx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
output, err := getBlock(cliCtx, &height)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
+7 -2
View File
@@ -2,6 +2,7 @@ package rpc
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
@@ -26,7 +27,9 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
// cli version REST handler endpoint
func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.Version)))
if _, err := w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.Version))); err != nil {
log.Printf("could not write response: %v", err)
}
}
// connected node version REST handler endpoint
@@ -39,6 +42,8 @@ func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc {
}
w.Header().Set("Content-Type", "application/json")
w.Write(version)
if _, err := w.Write(version); err != nil {
log.Printf("could not write response: %v", err)
}
}
}
+7 -7
View File
@@ -2,6 +2,7 @@ package rpc
import (
"fmt"
"log"
"net/http"
"strconv"
@@ -71,8 +72,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus(cliCtx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
@@ -86,18 +86,18 @@ func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus(cliCtx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
syncing := status.SyncInfo.CatchingUp
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
w.Write([]byte(strconv.FormatBool(syncing)))
if _, err := w.Write([]byte(strconv.FormatBool(syncing))); err != nil {
log.Printf("could not write response: %v", err)
}
}
}
+5 -10
View File
@@ -160,22 +160,19 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'."))
rest.WriteErrorResponse(w, http.StatusBadRequest, "ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'.")
return
}
chainHeight, err := GetChainHeight(cliCtx)
if height > chainHeight {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
rest.WriteErrorResponse(w, http.StatusNotFound, "ERROR: Requested block height is bigger then the chain length.")
return
}
output, err := getValidators(cliCtx, &height)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
@@ -187,15 +184,13 @@ func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerF
return func(w http.ResponseWriter, r *http.Request) {
height, err := GetChainHeight(cliCtx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
output, err := getValidators(cliCtx, &height)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
+1 -1
View File
@@ -110,7 +110,7 @@ $ gaiacli tx broadcast ./mytxn.json
}
res, err := cliCtx.BroadcastTx(txBytes)
cliCtx.PrintOutput(res)
cliCtx.PrintOutput(res) // nolint:errcheck
return err
},
}
+1 -1
View File
@@ -97,7 +97,7 @@ If you supply a dash (-) argument in place of an input filename, the command rea
txBytesBase64 := base64.StdEncoding.EncodeToString(txBytes)
response := txEncodeRespStr(txBytesBase64)
cliCtx.PrintOutput(response)
cliCtx.PrintOutput(response) // nolint:errcheck
return nil
},
+3 -2
View File
@@ -3,10 +3,11 @@ package utils
import (
"bytes"
"fmt"
"github.com/spf13/viper"
"io/ioutil"
"os"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
@@ -102,7 +103,7 @@ func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
// broadcast to a Tendermint node
res, err := cliCtx.BroadcastTx(txBytes)
cliCtx.PrintOutput(res)
cliCtx.PrintOutput(res) // nolint:errcheck
return err
}