Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Address linting issues #12851

Closed
wants to merge 19 commits into from
Closed
41 changes: 12 additions & 29 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
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:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read

jobs:
golangci:
permissions:
pull-requests: read # for technote-space/get-diff-action to get git reference
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.1.0
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
go-version: 1.19
faddat marked this conversation as resolved.
Show resolved Hide resolved
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
path: |
~/go/pkg/mod
~/.cache/golangci-lint
~/.cache/go-build
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Run golangci-lint
if: env.GIT_DIFF
run: make lint
# 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: --timeout 10m
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ linters:
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- gofumpt
- gosec
- gosimple
- govet
Expand All @@ -32,6 +31,9 @@ issues:
- text: "Use of weak random number generator"
linters:
- gosec
- text: "without leading space"
linters:
- nolintlint
- text: "comment on exported var"
linters:
- golint
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (ci) [#12851](https://github.com/cosmos/cosmos-sdk/pull/12851) Use canonical golangci-lint github action and lint grandfathered issues
* (x/bank) [#12706](https://github.com/cosmos/cosmos-sdk/pull/12706) Added the `chain-id` flag to the `AddTxFlagsToCmd` API. There is no longer a need to explicitly register this flag on commands whens `AddTxFlagsToCmd` is already called.
* [#12791](https://github.com/cosmos/cosmos-sdk/pull/12791) Bump the math library used in the sdk and replace old usages of sdk.*
* (x/params) [#12615](https://github.com/cosmos/cosmos-sdk/pull/12615) Add `GetParamSetIfExists` function to params `Subspace` to prevent panics on breaking changes.
Expand Down
16 changes: 8 additions & 8 deletions api/cosmos/base/query/v1beta1/pagination.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions api/cosmos/distribution/v1beta1/distribution.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions api/cosmos/group/v1/types.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type (
)

// BaseApp reflects the ABCI application implementation.
type BaseApp struct { // nolint: maligned
type BaseApp struct { //nolint: maligned
// initialized on creation
logger log.Logger
name string // application name from abci.Info
Expand Down
6 changes: 3 additions & 3 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (msr *MsgServiceRouter) HandlerByTypeURL(typeURL string) MsgServiceHandler
// service description, handler is an object which implements that gRPC service.
//
// This function PANICs:
// - if it is called before the service `Msg`s have been registered using
// RegisterInterfaces,
// - or if a service is being registered twice.
// - if it is called before the service `Msg`s have been registered using
// RegisterInterfaces,
// - or if a service is being registered twice.
func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler interface{}) {
// Adds a top-level query handler based on the gRPC service name.
for _, method := range sd.Methods {
Expand Down
11 changes: 6 additions & 5 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ func runAddCmdPrepare(cmd *cobra.Command, args []string) error {

/*
input
- bip39 mnemonic
- bip39 passphrase
- bip44 path
- local encryption password
- bip39 mnemonic
- bip39 passphrase
- bip44 path
- local encryption password

output
- armor encrypted private key (saved to file)
- armor encrypted private key (saved to file)
*/
func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *bufio.Reader) error {
var err error
Expand Down
10 changes: 6 additions & 4 deletions codec/amino_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func (ac *AminoCodec) MarshalInterface(i proto.Message) ([]byte, error) {
// NOTE: to unmarshal a concrete type, you should use Unmarshal instead
//
// Example:
// var x MyInterface
// err := cdc.UnmarshalInterface(bz, &x)
//
// var x MyInterface
// err := cdc.UnmarshalInterface(bz, &x)
func (ac *AminoCodec) UnmarshalInterface(bz []byte, ptr interface{}) error {
return ac.LegacyAmino.Unmarshal(bz, ptr)
}
Expand All @@ -117,8 +118,9 @@ func (ac *AminoCodec) MarshalInterfaceJSON(i proto.Message) ([]byte, error) {
// NOTE: to unmarshal a concrete type, you should use UnmarshalJSON instead
//
// Example:
// var x MyInterface
// err := cdc.UnmarshalInterfaceJSON(bz, &x)
//
// var x MyInterface
// err := cdc.UnmarshalInterfaceJSON(bz, &x)
func (ac *AminoCodec) UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error {
return ac.LegacyAmino.UnmarshalJSON(bz, ptr)
}
10 changes: 6 additions & 4 deletions codec/proto_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ func (pc *ProtoCodec) MarshalInterface(i gogoproto.Message) ([]byte, error) {
// NOTE: to unmarshal a concrete type, you should use Unmarshal instead
//
// Example:
// var x MyInterface
// err := cdc.UnmarshalInterface(bz, &x)
//
// var x MyInterface
// err := cdc.UnmarshalInterface(bz, &x)
func (pc *ProtoCodec) UnmarshalInterface(bz []byte, ptr interface{}) error {
any := &types.Any{}
err := pc.Unmarshal(bz, any)
Expand Down Expand Up @@ -233,8 +234,9 @@ func (pc *ProtoCodec) MarshalInterfaceJSON(x gogoproto.Message) ([]byte, error)
// NOTE: to unmarshal a concrete type, you should use UnmarshalJSON instead
//
// Example:
// var x MyInterface // must implement proto.Message
// err := cdc.UnmarshalInterfaceJSON(&x, bz)
//
// var x MyInterface // must implement proto.Message
// err := cdc.UnmarshalInterfaceJSON(&x, bz)
func (pc *ProtoCodec) UnmarshalInterfaceJSON(bz []byte, iface interface{}) error {
any := &types.Any{}
err := pc.UnmarshalJSON(bz, any)
Expand Down
12 changes: 6 additions & 6 deletions codec/unknownproto/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ b) Mismatched wire types for a field -- this is indicative of mismatched service

Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case

if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil {
// Handle the error.
}
if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil {
// Handle the error.
}

and ideally should be added before invoking proto.Unmarshal, if you'd like to enforce the features mentioned above.

By default, for security we report every single field that's unknown, whether a non-critical field or not. To customize
this behavior, please set the boolean parameter allowUnknownNonCriticals to true to RejectUnknownFields:

if err := RejectUnknownFields(protoBlob, protoMessage, true); err != nil {
// Handle the error.
}
if err := RejectUnknownFields(protoBlob, protoMessage, true); err != nil {
// Handle the error.
}
*/
package unknownproto
2 changes: 1 addition & 1 deletion cosmovisor/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (cfg *Config) SetCurrentUpgrade(u upgradetypes.Plan) (rerr error) {
return err
}
_, err = f.Write(bz)
return err
return err
}

func (cfg *Config) UpgradeInfo() (upgradetypes.Plan, error) {
Expand Down
5 changes: 3 additions & 2 deletions cosmovisor/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func (c *cosmovisorEnv) Set(envVar, envVal string) {

// clearEnv clears environment variables and what they were.
// Designed to be used like this:
// initialEnv := clearEnv()
// defer setEnv(nil, initialEnv)
//
// initialEnv := clearEnv()
// defer setEnv(nil, initialEnv)
func (s *argsTestSuite) clearEnv() *cosmovisorEnv {
s.T().Logf("Clearing environment variables.")
rv := cosmovisorEnv{}
Expand Down
5 changes: 3 additions & 2 deletions cosmovisor/cmd/cosmovisor/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func (c *cosmovisorHelpEnv) Set(envVar, envVal string) {

// clearEnv clears environment variables and returns what they were.
// Designed to be used like this:
// initialEnv := clearEnv()
// defer setEnv(nil, initialEnv)
//
// initialEnv := clearEnv()
// defer setEnv(nil, initialEnv)
func (s *HelpTestSuite) clearEnv() *cosmovisorHelpEnv {
s.T().Logf("Clearing environment variables.")
rv := cosmovisorHelpEnv{}
Expand Down
10 changes: 6 additions & 4 deletions cosmovisor/cmd/cosmovisor/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func (c *cosmovisorInitEnv) Set(envVar, envVal string) {

// clearEnv clears environment variables and returns what they were.
// Designed to be used like this:
// initialEnv := clearEnv()
// defer setEnv(nil, initialEnv)
//
// initialEnv := clearEnv()
// defer setEnv(nil, initialEnv)
func (s *InitTestSuite) clearEnv() *cosmovisorInitEnv {
s.T().Logf("Clearing environment variables.")
rv := cosmovisorInitEnv{}
Expand Down Expand Up @@ -137,8 +138,9 @@ func NewBufferedPipe(name string, replicateTo ...io.Writer) (BufferedPipe, error
// StartNewBufferedPipe creates a new BufferedPipe and starts it.
//
// This is functionally equivalent to:
// p, _ := NewBufferedPipe(name, replicateTo...)
// p.Start()
//
// p, _ := NewBufferedPipe(name, replicateTo...)
// p.Start()
func StartNewBufferedPipe(name string, replicateTo ...io.Writer) (BufferedPipe, error) {
p, err := NewBufferedPipe(name, replicateTo...)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions crypto/armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"io"

"github.com/tendermint/crypto/bcrypt"
"github.com/tendermint/tendermint/crypto"
"golang.org/x/crypto/openpgp/armor" // nolint: staticcheck
"golang.org/x/crypto/openpgp/armor" //nolint: staticcheck

"github.com/cosmos/cosmos-sdk/codec/legacy"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down Expand Up @@ -235,7 +235,7 @@ func DecodeArmor(armorStr string) (blockType string, headers map[string]string,
if err != nil {
return "", nil, nil, err
}
data, err = ioutil.ReadAll(block.Body)
data, err = io.ReadAll(block.Body)
if err != nil {
return "", nil, nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions crypto/hd/doc.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Package hd provides support for hierarchical deterministic wallets generation and derivation.
//
// The user must understand the overall concept of the BIP 32 and the BIP 44 specs:
// https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
//
// https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
//
// In combination with the bip39 package in go-crypto this package provides the functionality for
// deriving keys using a BIP 44 HD path, or, more general, by passing a BIP 32 path.
Expand Down
2 changes: 1 addition & 1 deletion crypto/hd/hdpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func DerivePrivateKeyForPath(privKeyBytes, chainCode [32]byte, path string) ([]b
// If harden is true, the derivation is 'hardened'.
// It returns the new private key and new chain code.
// For more information on hardened keys see:
// - https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
// - https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
func derivePrivateKey(privKeyBytes [32]byte, chainCode [32]byte, index uint32, harden bool) ([32]byte, [32]byte) {
var data []byte

Expand Down
Loading