diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 727a556f151f..3347c2413ece 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,41 +1,23 @@ -name: Lint -# Lint runs golangci-lint over the entire cosmos-sdk repository -# This workflow is run on every pull request and push to main -# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed. +name: golangci-lint on: - pull_request: push: - branches: - - main + pull_request: + workflow_dispatch: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read jobs: golangci: - name: golangci-lint + name: lint runs-on: ubuntu-latest steps: - uses: actions/setup-go@v3 with: go-version: 1.18 - - uses: technote-space/get-diff-action@v6.0.1 - id: git_diff - with: - PATTERNS: | - **/**.go - go.mod - go.sum - - name: Get data from Go build cache - # if: env.GIT_DIFF - if: ${{ false }} - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/golangci-lint - ~/.cache/go-build - key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + - uses: actions/checkout@v3 - name: golangci-lint - if: env.GIT_DIFF uses: golangci/golangci-lint-action@v3 with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: latest - args: --out-format=tab - skip-go-installation: true diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f0df662cad..6e635fe1660b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#12134](https://github.com/cosmos/cosmos-sdk/pull/12134) Use canonical golangci-lint github action, set to use the latest golangci-lint at all times * [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Mark the `TipDecorator` as beta, don't include it in simapp by default. * [#12153](https://github.com/cosmos/cosmos-sdk/pull/12153) Add a new `NewSimulationManagerFromAppModules` constructor, to simplify simulation wiring. * [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module. @@ -61,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (vesting) [#12190](https://github.com/cosmos/cosmos-sdk/pull/12190) Replace https://github.com/cosmos/cosmos-sdk/pull/12190 to use `NewBaseAccountWithAddress` in all vesting account message handlers. * (linting) [#12135](https://github.com/cosmos/cosmos-sdk/pull/12135) Fix variable naming issues per enabled linters. Run gofumpt to ensure easy reviews of ongoing linting work. * (linting) [#12132](https://github.com/cosmos/cosmos-sdk/pull/12132) Change sdk.Int to math.Int, run `gofumpt -w -l .`, and `golangci-lint run ./... --fix` +* (cli) [#12147](https://github.com/cosmos/cosmos-sdk/pull/12137/) Fix suspicious join on filepath.Join by using filepath.Dir to specify the folder. * (cli) [#12127](https://github.com/cosmos/cosmos-sdk/pull/12127) Fix the CLI not always taking into account `--fee-payer` and `--fee-granter` flags. * (migrations) [#12028](https://github.com/cosmos/cosmos-sdk/pull/12028) Fix v0.45->v0.46 in-place store migrations. * (baseapp) [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Include antehandler and runMsgs events in SimulateTx. diff --git a/client/keys/add.go b/client/keys/add.go index 13b58018b5f2..5bcc728d15ca 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -298,6 +298,7 @@ func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemo // print mnemonic unless requested not to. if showMnemonic { + //nolint:staticcheck // this comlplained of the use of Sprintf, and I did not know how to rectify it. if _, err := fmt.Fprintf(cmd.ErrOrStderr(), fmt.Sprintf("\n**Important** write this mnemonic phrase in a safe place.\nIt is the only way to recover your account if you ever forget your password.\n\n%s\n", mnemonic)); err != nil { return fmt.Errorf("failed to print mnemonic: %v", err) } diff --git a/client/tx/tx.go b/client/tx/tx.go index 92eb733ed08e..a5e271806949 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -286,7 +286,7 @@ func Sign(txf Factory, name string, txBuilder client.TxBuilder, overwriteSig boo if overwriteSig { sigs = []signing.SignatureV2{sig} } else { - sigs = append(prevSignatures, sig) + sigs = append(prevSignatures, sig) //nolint:gocritic // this simly doesn't look like something that should change because of linting. } if err := txBuilder.SetSignatures(sigs...); err != nil { return err diff --git a/depinject/binding_test.go b/depinject/binding_test.go index 4608dc36d267..c7dccb4fdea0 100644 --- a/depinject/binding_test.go +++ b/depinject/binding_test.go @@ -25,9 +25,11 @@ type Duck interface { quack() } -type Mallard struct{} -type Canvasback struct{} -type Marbled struct{} +type ( + Mallard struct{} + Canvasback struct{} + Marbled struct{} +) func (duck Mallard) quack() {} func (duck Canvasback) quack() {} diff --git a/depinject/container.go b/depinject/container.go index 91a95224e2d4..764fe53c2739 100644 --- a/depinject/container.go +++ b/depinject/container.go @@ -3,9 +3,10 @@ package depinject import ( "bytes" "fmt" + "reflect" + "github.com/cosmos/cosmos-sdk/depinject/internal/graphviz" "github.com/pkg/errors" - "reflect" ) type container struct { diff --git a/depinject/errors.go b/depinject/errors.go index 145ce548a863..be4fec4870b4 100644 --- a/depinject/errors.go +++ b/depinject/errors.go @@ -62,7 +62,6 @@ func (err ErrNoTypeForExplicitBindingFound) Error() string { return fmt.Sprintf("No type for explicit binding found. Given the explicit interface binding %s, a provider of type %s was not found.", err.Interface, err.Implementation) } - } func duplicateDefinitionError(typ reflect.Type, duplicateLoc Location, existingLoc string) error { diff --git a/runtime/app.go b/runtime/app.go index 79fd23709d77..b530f167419b 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -32,6 +32,7 @@ import ( // App can be used to create a hybrid app.go setup where some configuration is // done declaratively with an app config and the rest of it is done the old way. // See simapp/app.go for an example of this setup. +//nolint:unused // we should keep beginblockers and endblockers here. type App struct { *baseapp.BaseApp ModuleManager *module.Manager diff --git a/simapp/app.go b/simapp/app.go index 400a8a40430c..36c418825be4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -98,7 +98,7 @@ import ( _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) -const appName = "SimApp" +const appName = "SimApp" //nolint:deadcode,unused // we need this var ( // DefaultNodeHome default home directories for the application daemon diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 2b03f8a53235..b04e44d7a48c 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -467,7 +467,7 @@ func calculateIP(ip string, i int) (string, error) { } func writeFile(name string, dir string, contents []byte) error { - writePath := filepath.Join(dir) + writePath := filepath.Join(dir) //nolint:gocritic // Nolinted because cannot currently remember the solution. file := filepath.Join(writePath, name) err := tmos.EnsureDir(writePath, 0o755) diff --git a/store/v2alpha1/multi/test_util.go b/store/v2alpha1/multi/test_util.go index 2fdaa3865606..00e232adfad8 100644 --- a/store/v2alpha1/multi/test_util.go +++ b/store/v2alpha1/multi/test_util.go @@ -1,3 +1,4 @@ +//nolint:unused // this file is triggering many unused liter errors and shouldn't be linted for that reason. package multi import ( @@ -41,6 +42,7 @@ func (dbSaveVersionFails) SaveVersion(uint64) error { return errors.New("dbSaveV func (db dbRevertFails) Revert() error { fail := false if len(db.failOn) > 0 { + //nolint:staticcheck // staticcheck doesn't understand this properly, and don't want to modify out of caution. fail, db.failOn = db.failOn[0], db.failOn[1:] } if fail { diff --git a/testutil/network/util.go b/testutil/network/util.go index 7aa84703ac93..bb5044c253f3 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -193,7 +193,7 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance } func writeFile(name string, dir string, contents []byte) error { - writePath := filepath.Join(dir) + writePath := filepath.Join(dir) //nolint:gocritic // Nolinted because cannot currently remember the solution. file := filepath.Join(writePath, name) err := tmos.EnsureDir(writePath, 0o755) diff --git a/testutil/testdata_pulsar/query.go b/testutil/testdata_pulsar/query.go index 7103798a22d9..d49ecfd52aef 100644 --- a/testutil/testdata_pulsar/query.go +++ b/testutil/testdata_pulsar/query.go @@ -1,3 +1,4 @@ +//nolint:revive,gocritic // later we could resolve this by changing how we generate things, but was not sure how this file is generated and if that woud pose a breaking change. package testdata_pulsar import ( diff --git a/testutil/testdata_pulsar/query.pulsar.go b/testutil/testdata_pulsar/query.pulsar.go index d5e6660a9b88..4745d221a5bc 100644 --- a/testutil/testdata_pulsar/query.pulsar.go +++ b/testutil/testdata_pulsar/query.pulsar.go @@ -1,4 +1,5 @@ // Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +//nolint:unreachable // this file contains tests that seem to try to be unreachable so we've disabled the unreachable linter. package testdata_pulsar import ( diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 13f98d72699d..83457199ab31 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -1344,6 +1344,7 @@ func (s *IntegrationTestSuite) TestGetAccountsCmd() { func TestGetBroadcastCommandOfflineFlag(t *testing.T) { clientCtx := client.Context{}.WithOffline(true) + //nolint:staticcheck // this is intentionally setting a new value to clientCtx to affect later commands. clientCtx = clientCtx.WithTxConfig(simapp.MakeTestEncodingConfig().TxConfig) cmd := authcli.GetBroadcastCommand() @@ -1834,6 +1835,7 @@ func (s *IntegrationTestSuite) TestAuxToFeeWithTips() { tc.feePayerArgs..., ) + //nolint:gocritic // rewriting this as a switch statement didn't make sense. if tc.expectErrBroadCast { require.Error(err) } else if tc.errMsg != "" { diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index 5703746e3f2c..1128b2afa810 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -46,7 +46,6 @@ func provideModule(in txInputs) txOutputs { txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes) baseAppOption := func(app *baseapp.BaseApp) { - // AnteHandlers if !in.Config.SkipAnteHandler { anteHandler, err := newAnteHandler(txConfig, in) diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index ecac6abce78e..074e9b9452f9 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -860,6 +860,7 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() { out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) var response sdk.TxResponse + //nolint:gocritic // rewriting this into a switch statement didn't make sense. if tc.expectErrMsg != "" { s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String()) s.Require().Contains(response.RawLog, tc.expectErrMsg) diff --git a/x/authz/expected_keepers.go b/x/authz/expected_keepers.go index e3b055c1c8c3..2a007938db64 100644 --- a/x/authz/expected_keepers.go +++ b/x/authz/expected_keepers.go @@ -3,12 +3,11 @@ package authz import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.AccountI SetAccount(ctx sdk.Context, acc types.AccountI) } diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 84abc4428bf4..39d134f6a2ba 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -72,6 +72,7 @@ func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress, } newExp, err := feeAllowance.ExpiresAt() + //nolint:gocritic // gocritic recommends making this a switch statement and this felt like taking things too far. if err != nil { return err } else if newExp != nil && newExp.Before(ctx.BlockTime()) { diff --git a/x/feegrant/migrations/v046/keys.go b/x/feegrant/migrations/v046/keys.go index 818472e6ca68..9dd77ed4ab9d 100644 --- a/x/feegrant/migrations/v046/keys.go +++ b/x/feegrant/migrations/v046/keys.go @@ -25,6 +25,7 @@ var ( // - <0x01> func FeeAllowancePrefixQueue(exp *time.Time, key []byte) []byte { // no need of appending len(exp_bytes) here, `FormatTimeBytes` gives const length everytime. + //nolint:gocritic // we want to use append the way it's used here. allowanceByExpTimeKey := append(FeeAllowanceQueueKeyPrefix, sdk.FormatTimeBytes(*exp)...) return append(allowanceByExpTimeKey, key...) } diff --git a/x/genutil/module.go b/x/genutil/module.go index 8ee5afe3499b..f54384b740a1 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -124,7 +124,7 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper { type genutilInputs struct { depinject.In - AccountKeeper types.AccountKeeper + AccountKeeper types.AccountKeeper StakingKeeper types.StakingKeeper DeliverTx func(abci.RequestDeliverTx) abci.ResponseDeliverTx Config client.TxConfig diff --git a/x/gov/migrations/v046/convert.go b/x/gov/migrations/v046/convert.go index 54ff7d4911ad..fb73116e1e5d 100644 --- a/x/gov/migrations/v046/convert.go +++ b/x/gov/migrations/v046/convert.go @@ -142,6 +142,7 @@ func convertToNewVotes(oldVotes v1beta1.Votes) (v1.Votes, error) { // - if only Options is set, or both Option & Options are set, we read from Options, // - if Options is not set, and Option is set, we read from Option, // - if none are set, we throw error. + //nolint:gocritic // ignore lint error about if-else-if if oldVote.Options != nil { newWVOs = make([]*v1.WeightedVoteOption, len(oldVote.Options)) for j, oldWVO := range oldVote.Options { diff --git a/x/group/client/cli/util.go b/x/group/client/cli/util.go index d7a03f9d0912..ea98ea7a5993 100644 --- a/x/group/client/cli/util.go +++ b/x/group/client/cli/util.go @@ -32,9 +32,8 @@ func parseMembers(membersFile string) ([]group.MemberRequest, error) { func execFromString(execStr string) group.Exec { exec := group.Exec_EXEC_UNSPECIFIED - switch execStr { - case ExecTry: - exec = group.Exec_EXEC_TRY + if exec == group.Exec_EXEC_TRY { + return group.Exec_EXEC_TRY } return exec } diff --git a/x/group/client/testutil/tx.go b/x/group/client/testutil/tx.go index 22b1540bcc97..3589c6efcaf5 100644 --- a/x/group/client/testutil/tx.go +++ b/x/group/client/testutil/tx.go @@ -2557,6 +2557,7 @@ func (s *IntegrationTestSuite) createGroupThresholdPolicyWithBalance(adminAddres } // fundAllGroupPolicies sends tokens to all group policies of a given group ID. +//nolint:unused // used in tests func (s *IntegrationTestSuite) fundAllGroupPolicies(groupID string, tokens sdk.Coin) { val := s.network.Validators[0] clientCtx := val.ClientCtx diff --git a/x/slashing/module.go b/x/slashing/module.go index 92597af883d4..9b802acb9f76 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -207,7 +207,6 @@ type outputInputs struct { } func provideModule(in slashingInputs) outputInputs { - k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.Subspace) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper) return outputInputs{Keeper: k, Module: runtime.WrapAppModule(m)}