Skip to content

Commit

Permalink
update golangci-lint fix (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
nghuyenthevinh2000 authored Mar 20, 2023
1 parent b54f04d commit 04401e3
Show file tree
Hide file tree
Showing 114 changed files with 427 additions and 477 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand All @@ -24,7 +24,7 @@ jobs:
- uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.51.2
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: "env.GIT_DIFF != ''"
79 changes: 59 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
run:
tests: true
timeout: 10m
sort-results: true
allow-parallel-runners: true
concurrency: 4

linters:
disable-all: true
enable:
- errcheck
- golint
- ineffassign
- unconvert
- misspell
- govet
# - unused
# - deadcode
- depguard
- dogsled
- exportloopref
- goconst
- gocritic
- gofumpt
- gosec
# - staticcheck
linters-settings:
gocyclo:
min-complexity: 11
errcheck:
ignore: fmt:.*,io/ioutil:^Read.*,github.com/spf13/cobra:MarkFlagRequired,github.com/spf13/viper:BindPFlag
golint:
min-confidence: 1.1
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- nolintlint
- staticcheck
- revive
- stylecheck
- typecheck
- unconvert
- unused

issues:
exclude:
- composite
run:
tests: false
exclude-rules:
- text: "Use of weak random number generator"
linters:
- gosec
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck
- text: "leading space"
linters:
- nolintlint

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import (

// upgrades
"github.com/classic-terra/core/app/upgrades"
"github.com/classic-terra/core/app/upgrades/v2"
"github.com/classic-terra/core/app/upgrades/v3"
v2 "github.com/classic-terra/core/app/upgrades/v2"
v3 "github.com/classic-terra/core/app/upgrades/v3"

customante "github.com/classic-terra/core/custom/auth/ante"
customauthrest "github.com/classic-terra/core/custom/auth/client/rest"
Expand Down Expand Up @@ -79,7 +79,7 @@ var (
// TerraApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type TerraApp struct { // nolint: golint
type TerraApp struct {
*baseapp.BaseApp
keepers.AppKeepers

Expand Down
4 changes: 2 additions & 2 deletions app/legacy/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package legacy
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"time"

Expand Down Expand Up @@ -54,7 +54,7 @@ $ terrad migrate /path/to/genesis.json --chain-id=cosmoshub-4 --genesis-time=201

importGenesis := args[0]

jsonBlob, err := ioutil.ReadFile(importGenesis)
jsonBlob, err := os.ReadFile(importGenesis)
if err != nil {
return errors.Wrap(err, "failed to read provided genesis file")
}
Expand Down
4 changes: 2 additions & 2 deletions app/legacy/pubkey_replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"

"github.com/pkg/errors"
cryptocodec "github.com/tendermint/tendermint/crypto/encoding"
Expand Down Expand Up @@ -38,7 +38,7 @@ type replacementConfig struct {
}

func loadKeydataFromFile(clientCtx client.Context, replacementrJSON string, genDoc *tmtypes.GenesisDoc) *tmtypes.GenesisDoc {
jsonReplacementBlob, err := ioutil.ReadFile(replacementrJSON)
jsonReplacementBlob, err := os.ReadFile(replacementrJSON)
if err != nil {
log.Fatal(errors.Wrapf(err, "failed to read replacement keys from file %s", replacementrJSON))
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/terrad/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -58,7 +57,7 @@ $ terrad add-genesis-account acc1 '10000000000uluna,1000000ukrw'
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
depCdc := clientCtx.Codec
cdc := depCdc.(codec.Codec)
cdc := depCdc

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
Expand Down
2 changes: 1 addition & 1 deletion cmd/terrad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {

sdkConfig := sdk.GetConfig()
sdkConfig.SetCoinType(core.CoinType)
sdkConfig.SetFullFundraiserPath(core.FullFundraiserPath)
sdkConfig.SetPurpose(core.Purpose)
sdkConfig.SetBech32PrefixForAccount(core.Bech32PrefixAccAddr, core.Bech32PrefixAccPub)
sdkConfig.SetBech32PrefixForValidator(core.Bech32PrefixValAddr, core.Bech32PrefixValPub)
sdkConfig.SetBech32PrefixForConsensusNode(core.Bech32PrefixConsAddr, core.Bech32PrefixConsPub)
Expand Down
23 changes: 11 additions & 12 deletions cmd/terrad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -138,7 +139,7 @@ func InitTestnet(

inBuf := bufio.NewReader(cmd.InOrStdin())
// generate private keys, node IDs, and initial transactions

// can have 6 validators at most
// but need to go through all nodes to initialize config and such
for i := 0; i < 6; i++ {
Expand All @@ -148,7 +149,7 @@ func InitTestnet(

nodeConfig.SetRoot(nodeDir)
nodeConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657"

// 1.) create testnet config dirs
if err := os.MkdirAll(filepath.Join(nodeDir, "config"), nodeDirPerm); err != nil {
_ = os.RemoveAll(outputDir)
Expand All @@ -172,7 +173,6 @@ func InitTestnet(
return err
}


memo := fmt.Sprintf("%s@%s:26656", nodeIDs[i], ip)
genFiles = append(genFiles, nodeConfig.GenesisFile())

Expand All @@ -187,7 +187,7 @@ func InitTestnet(
return err
}

addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, true, algo)
addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, "", true, algo)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
Expand All @@ -204,14 +204,13 @@ func InitTestnet(
if err := writeFile(fmt.Sprintf("%v.json", "key_seed"), nodeDir, cliPrint); err != nil {
return err
}

// create account Tokens for node
accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)

// create staking tokens for node
accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction)



coins := sdk.Coins{
sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), accTokens),
sdk.NewCoin(core.MicroLunaDenom, accStakingTokens),
Expand All @@ -220,7 +219,7 @@ func InitTestnet(
genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))
valTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)

// create gentxs only for numValidators
if i < numValidators {
// create the validator for node i
Expand All @@ -235,7 +234,7 @@ func InitTestnet(
if err != nil {
return err
}

// create gentx (create validator) and write to file
txBuilder := clientCtx.TxConfig.NewTxBuilder()
if err := txBuilder.SetMsgs(createValMsg); err != nil {
Expand All @@ -259,7 +258,7 @@ func InitTestnet(
return err
}
}

// write config file app.toml
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), terraappConfig)
}
Expand Down Expand Up @@ -396,7 +395,7 @@ func calculateIP(ip string, i int) (string, error) {
}

func writeFile(name string, dir string, contents []byte) error {
writePath := filepath.Join(dir)
writePath := dir
file := filepath.Join(writePath, name)

err := tmos.EnsureDir(writePath, 0o755)
Expand Down
11 changes: 5 additions & 6 deletions custom/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

Expand Down Expand Up @@ -139,11 +138,11 @@ func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptoty
// TODO: also generate ed25519 keys as below when ed25519 keys are
// actually supported, https://github.com/cosmos/cosmos-sdk/issues/4789
// for now this fails:
//if rand.Int63()%2 == 0 {
// if rand.Int63()%2 == 0 {
// privkey = ed25519.GenPrivKey()
//} else {
// } else {
// privkey = secp256k1.GenPrivKey()
//}
// }

pubkeys[i] = privkey.PubKey()
signatures[i], _ = privkey.Sign(msg)
Expand All @@ -157,9 +156,9 @@ func expectedGasCostByKeys(pubkeys []cryptotypes.PubKey) uint64 {
pubkeyType := strings.ToLower(fmt.Sprintf("%T", pubkey))
switch {
case strings.Contains(pubkeyType, "ed25519"):
cost += types.DefaultParams().SigVerifyCostED25519
cost += authtypes.DefaultParams().SigVerifyCostED25519
case strings.Contains(pubkeyType, "secp256k1"):
cost += types.DefaultParams().SigVerifyCostSecp256k1
cost += authtypes.DefaultParams().SigVerifyCostSecp256k1
default:
panic("unexpected key type")
}
Expand Down
3 changes: 2 additions & 1 deletion custom/auth/ante/burntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {
require.Equal(amountFeeBefore, taxes)

totalSupplyBefore, _, err := bk.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{})
require.NoError(err)
fmt.Printf(
"Before: TotalSupply %v, Community %v, FeeCollector %v\n",
totalSupplyBefore,
Expand Down Expand Up @@ -96,7 +97,7 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {
tk.BurnCoinsFromBurnAccount(suite.ctx)

totalSupplyAfter, _, err := bk.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{})

require.NoError(err)
if !burnTax.Empty() {
// expected: total supply = tax - split tax
require.Equal(
Expand Down
5 changes: 2 additions & 3 deletions custom/auth/ante/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ante_test
import (
"fmt"

"github.com/classic-terra/core/custom/auth/ante"
customante "github.com/classic-terra/core/custom/auth/ante"
core "github.com/classic-terra/core/types"
treasurytypes "github.com/classic-terra/core/x/treasury/types"
Expand Down Expand Up @@ -136,7 +135,7 @@ func (suite *AnteTestSuite) TestIntegrationTaxExemption() {
FeegrantKeeper: suite.app.FeeGrantKeeper,
OracleKeeper: suite.app.OracleKeeper,
TreasuryKeeper: suite.app.TreasuryKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
SigGasConsumer: customante.DefaultSigVerificationGasConsumer,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
IBCChannelKeeper: suite.app.IBCKeeper.ChannelKeeper,
DistributionKeeper: dk,
Expand All @@ -145,7 +144,7 @@ func (suite *AnteTestSuite) TestIntegrationTaxExemption() {
suite.Require().NoError(err)

fmt.Printf("CASE = %s \n", c.name)
suite.ctx = suite.ctx.WithBlockHeight(ante.TaxPowerUpgradeHeight)
suite.ctx = suite.ctx.WithBlockHeight(customante.TaxPowerUpgradeHeight)
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

tk.AddBurnTaxExemptionAddress(suite.ctx, addrs[0].String())
Expand Down
5 changes: 3 additions & 2 deletions custom/auth/ante/min_initial_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante

import (
"fmt"

core "github.com/classic-terra/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -33,7 +34,7 @@ func IsMsgSubmitProposal(msg sdk.Msg) bool {
func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper govkeeper.Keeper, treasuryKeeper TreasuryKeeper) (err error) {
submitPropMsg, ok := msg.(*govtypes.MsgSubmitProposal)
if !ok {
return fmt.Errorf("Could not dereference msg as MsgSubmitProposal")
return fmt.Errorf("could not dereference msg as MsgSubmitProposal")
}

minDeposit := govKeeper.GetDepositParams(ctx).MinDeposit
Expand All @@ -45,7 +46,7 @@ func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper govkee
initialDepositCoins := submitPropMsg.GetInitialDeposit()

if !initialDepositCoins.IsAllGTE(requiredDepositCoins) {
return fmt.Errorf("Not enough initial deposit provided. Expected %q; got %q", requiredDepositCoins, initialDepositCoins)
return fmt.Errorf("not enough initial deposit provided. Expected %q; got %q", requiredDepositCoins, initialDepositCoins)
}

return nil
Expand Down
Loading

0 comments on commit 04401e3

Please sign in to comment.