Merge PR #4608: More linters - Gosec, staticcheck

This commit is contained in:
Marko 2019-06-26 22:30:36 +02:00 committed by Jack Zampolin
parent c898dac6a9
commit b2f8c58ec4
12 changed files with 44 additions and 47 deletions

View File

@ -50,22 +50,6 @@ jobs:
- bin - bin
- profiles - profiles
lint:
<<: *linux_defaults
parallelism: 1
steps:
- attach_workspace:
at: /tmp/workspace
- checkout
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Lint source
command: |
export PATH=/tmp/workspace/bin:$PATH
make ci-lint
test_sim_app_nondeterminism: test_sim_app_nondeterminism:
<<: *linux_defaults <<: *linux_defaults
parallelism: 1 parallelism: 1
@ -284,9 +268,6 @@ workflows:
tags: tags:
only: only:
- /^v.*/ - /^v.*/
- lint:
requires:
- setup_dependencies
- test_sim_app_nondeterminism: - test_sim_app_nondeterminism:
requires: requires:
- setup_dependencies - setup_dependencies

View File

@ -10,6 +10,8 @@ linters:
- unused - unused
- deadcode - deadcode
- goconst - goconst
- gosec
- staticcheck
linters-settings: linters-settings:
gocyclo: gocyclo:
min-complexity: 11 min-complexity: 11

View File

@ -65,23 +65,21 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error)
// "y", "Y", "yes", "YES", and "Yes" all count as confirmations. // "y", "Y", "yes", "YES", and "Yes" all count as confirmations.
// If the input is not recognized, it returns false and a nil error. // If the input is not recognized, it returns false and a nil error.
func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) { func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
for { if inputIsTty() {
if inputIsTty() { fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt))
fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt))
}
response, err := readLineFromBuf(buf)
if err != nil {
return false, err
}
response = strings.ToLower(strings.TrimSpace(response))
if response[0] == 'y' {
return true, nil
}
return false, nil
} }
response, err := readLineFromBuf(buf)
if err != nil {
return false, err
}
response = strings.ToLower(strings.TrimSpace(response))
if response[0] == 'y' {
return true, nil
}
return false, nil
} }
// GetString simply returns the trimmed string output of a given reader. // GetString simply returns the trimmed string output of a given reader.

View File

@ -117,13 +117,16 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
height, err := strconv.ParseInt(vars["height"], 10, 64) height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil { if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, rest.WriteErrorResponse(w, http.StatusBadRequest,
"ERROR: Couldn't parse block height. Assumed format is '/block/{height}'.") "couldn't parse block height. Assumed format is '/block/{height}'.")
return return
} }
chainHeight, err := GetChainHeight(cliCtx) chainHeight, err := GetChainHeight(cliCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
return
}
if height > chainHeight { if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound, rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
"ERROR: Requested block height is bigger then the chain length.")
return return
} }
output, err := getBlock(cliCtx, &height) output, err := getBlock(cliCtx, &height)

View File

@ -161,13 +161,17 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
height, err := strconv.ParseInt(vars["height"], 10, 64) height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil { if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'.") rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse block height; assumed format is '/validatorsets/{height}'")
return return
} }
chainHeight, err := GetChainHeight(cliCtx) chainHeight, err := GetChainHeight(cliCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
return
}
if height > chainHeight { if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound, "ERROR: Requested block height is bigger then the chain length.") rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
return return
} }

View File

@ -16,7 +16,7 @@ import (
// Get a free address for a test tendermint server // Get a free address for a test tendermint server
// protocol is either tcp, http, etc // protocol is either tcp, http, etc
func FreeTCPAddr() (addr, port string, err error) { func FreeTCPAddr() (addr, port string, err error) {
l, err := net.Listen("tcp", "0.0.0.0:0") l, err := net.Listen("tcp", "localhost:0")
if err != nil { if err != nil {
return "", "", err return "", "", err
} }

View File

@ -99,6 +99,9 @@ func interceptLoadConfig() (conf *cfg.Config, err error) {
if conf == nil { if conf == nil {
conf, err = tcmd.ParseConfig() // NOTE: ParseConfig() creates dir/files as necessary. conf, err = tcmd.ParseConfig() // NOTE: ParseConfig() creates dir/files as necessary.
if err != nil {
panic(err)
}
} }
appConfigFilePath := filepath.Join(rootDir, "config/app.toml") appConfigFilePath := filepath.Join(rootDir, "config/app.toml")

View File

@ -133,7 +133,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str
iter := sdk.KVStoreReversePrefixIterator(store, staking.ValidatorsKey) iter := sdk.KVStoreReversePrefixIterator(store, staking.ValidatorsKey)
counter := int16(0) counter := int16(0)
var valConsAddrs []sdk.ConsAddress
for ; iter.Valid(); iter.Next() { for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:]) addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.stakingKeeper.GetValidator(ctx, addr) validator, found := app.stakingKeeper.GetValidator(ctx, addr)
@ -142,7 +141,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str
} }
validator.UnbondingHeight = 0 validator.UnbondingHeight = 0
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
if applyWhiteList && !whiteListMap[addr.String()] { if applyWhiteList && !whiteListMap[addr.String()] {
validator.Jailed = true validator.Jailed = true
} }

View File

@ -97,7 +97,8 @@ func waitForHeight(height int64, url string) {
var res *http.Response var res *http.Response
var err error var err error
for { for {
res, err = http.Get(url) // Since this is in a testing file we are accepting nolint to be passed
res, err = http.Get(url) //nolint:gosec
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -150,7 +151,7 @@ func WaitForStart(url string) {
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
var res *http.Response var res *http.Response
res, err = http.Get(url) res, err = http.Get(url) //nolint:gosec Error is arising in testing files, accepting nolint
if err != nil || res == nil { if err != nil || res == nil {
continue continue
} }
@ -214,3 +215,5 @@ var cdc = codec.New()
func init() { func init() {
ctypes.RegisterAmino(cdc) ctypes.RegisterAmino(cdc)
} }
//DONTCOVER

View File

@ -214,10 +214,10 @@ func readUnsignedGenTxFile(cdc *codec.Codec, r io.Reader) (auth.StdTx, error) {
func writeSignedGenTx(cdc *codec.Codec, outputDocument string, tx auth.StdTx) error { func writeSignedGenTx(cdc *codec.Codec, outputDocument string, tx auth.StdTx) error {
outputFile, err := os.OpenFile(outputDocument, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) outputFile, err := os.OpenFile(outputDocument, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
defer outputFile.Close()
if err != nil { if err != nil {
return err return err
} }
defer outputFile.Close()
json, err := cdc.MarshalJSON(tx) json, err := cdc.MarshalJSON(tx)
if err != nil { if err != nil {
return err return err

View File

@ -163,7 +163,7 @@ func operationSimulateMsgVote(k gov.Keeper, acc simulation.Account, proposalID u
acc = simulation.RandomAcc(r, accs) acc = simulation.RandomAcc(r, accs)
} }
if proposalID < 0 { if proposalID < uint64(0) {
var ok bool var ok bool
proposalID, ok = randomProposalID(r, k, ctx) proposalID, ok = randomProposalID(r, k, ctx)
if !ok { if !ok {

View File

@ -42,6 +42,11 @@ func queryBonds(cliCtx context.CLIContext, endpoint string) http.HandlerFunc {
bech32validator := vars["validatorAddr"] bech32validator := vars["validatorAddr"]
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator) delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
validatorAddr, err := sdk.ValAddressFromBech32(bech32validator) validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
if err != nil { if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())