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

fix: make linting work on 45 #13185

Merged
merged 10 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
name: Lint
# Lint runs golangci-lint over the entire cosmos-sdk repository
# This workflow is run on every pull request and push to master
# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed.
on:
pull_request:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2.1.4
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: technote-space/get-diff-action@v5
id: git_diff
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: run go linters
run: make lint-go
if: env.GIT_DIFF
# 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
30 changes: 8 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,30 @@ run:
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
# - errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- revive
- exportloopref
- nolintlint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
- misspell
# - wsl
- nolintlint

issues:
exclude-rules:
- text: "Use of weak random number generator"
linters:
- gosec
- text: "comment on exported var"
linters:
- golint
- text: "don't use an underscore in package name"
linters:
- golint
- text: "ST1003:"
linters:
- stylecheck
Expand All @@ -54,7 +38,10 @@ issues:
- text: "ST1016:"
linters:
- stylecheck
- path: "legacy"
- text: "should be written without leading space as"
linters:
- nolintlint
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck
Expand All @@ -70,6 +57,5 @@ linters-settings:
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
require-specific: false
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@ lint-go:
.PHONY: lint lint-fix

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name "*.pb.go" -not -name "*.pb.gw.go" -not -name "*.pulsar.go" -not -path "./crypto/keys/secp256k1/*" | xargs gofumpt -w -l
golangci-lint run --fix
.PHONY: format

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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
3 changes: 1 addition & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"strings"
Expand Down Expand Up @@ -134,7 +133,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options

snapshotInterval := uint64(2)
snapshotTimeout := 1 * time.Minute
snapshotDir, err := ioutil.TempDir("", "baseapp")
snapshotDir, err := os.MkdirTemp("", "baseapp")
require.NoError(t, err)
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snapshotDir)
require.NoError(t, err)
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
4 changes: 2 additions & 2 deletions client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config_test
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"testing"

Expand Down Expand Up @@ -58,7 +58,7 @@ func TestConfigCmd(t *testing.T) {
cmd.SetOut(b)
cmd.SetArgs([]string{"node"})
cmd.Execute()
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Equal(t, string(out), testNode1+"\n")
}
Expand Down
3 changes: 1 addition & 2 deletions client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"bytes"
"io/ioutil"
"os"
"text/template"

Expand Down Expand Up @@ -43,7 +42,7 @@ func writeConfigToFile(configFilePath string, config *ClientConfig) error {
return err
}

return ioutil.WriteFile(configFilePath, buffer.Bytes(), 0o600)
return os.WriteFile(configFilePath, buffer.Bytes(), 0o600)
}

// ensureConfigPath creates a directory configPath if it does not exist
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
4 changes: 2 additions & 2 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -179,7 +179,7 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
_, err = kb.Key("testkey")
require.NoError(t, err)

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Contains(t, string(out), "name: testkey")
} else {
Expand Down
4 changes: 2 additions & 2 deletions client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -218,7 +218,7 @@ func Test_runAddCmdDryRun(t *testing.T) {
_, err = kb.Key("testkey")
require.NoError(t, err)

out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Contains(t, string(out), "name: testkey")
} else {
Expand Down
4 changes: 2 additions & 2 deletions client/keys/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keys

import (
"bufio"
"io/ioutil"
"os"

"github.com/spf13/cobra"

Expand All @@ -24,7 +24,7 @@ func ImportKeyCommand() *cobra.Command {
}
buf := bufio.NewReader(clientCtx.Input)

bz, err := ioutil.ReadFile(args[1])
bz, err := os.ReadFile(args[1])
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keys
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -95,7 +94,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO

keyfile := filepath.Join(kbHome, "key.asc")

require.NoError(t, ioutil.WriteFile(keyfile, []byte(armoredKey), 0o644))
require.NoError(t, os.WriteFile(keyfile, []byte(armoredKey), 0o644))

defer func() {
_ = os.RemoveAll(kbHome)
Expand Down
3 changes: 1 addition & 2 deletions client/keys/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keys
import (
"bufio"
"fmt"
"io/ioutil"
"os"

"github.com/pkg/errors"
Expand Down Expand Up @@ -68,7 +67,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
)

if dryRun, _ := cmd.Flags().GetBool(flags.FlagDryRun); dryRun {
tmpDir, err = ioutil.TempDir("", "migrator-migrate-dryrun")
tmpDir, err = os.MkdirTemp("", "migrator-migrate-dryrun")
if err != nil {
return errors.Wrap(err, "failed to create temporary directory for dryrun migration")
}
Expand Down
1 change: 0 additions & 1 deletion client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func addHTTPDeprecationHeaders(h http.Handler) http.Handler {
// WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input
// but with the addition of HTTP Deprecation headers. This is used to mark legacy
// amino REST endpoints as deprecated in the REST API.
// nolint: gocritic
func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router {
subRouter := r.NewRoute().Subrouter()
subRouter.Use(addHTTPDeprecationHeaders)
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 @@ -200,8 +200,9 @@ func (pc *ProtoCodec) 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 (pc *ProtoCodec) UnmarshalInterface(bz []byte, ptr interface{}) error {
any := &types.Any{}
err := pc.Unmarshal(bz, any)
Expand Down Expand Up @@ -229,8 +230,9 @@ func (pc *ProtoCodec) MarshalInterfaceJSON(x proto.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
4 changes: 0 additions & 4 deletions codec/types/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ type Any struct {
// Schemes other than `http`, `https` (or the empty scheme) might be
// used with implementation specific semantics.

// nolint
TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
// Must be a valid serialized protocol buffer of the above specified type.
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`

// nolint
XXX_NoUnkeyedLiteral struct{} `json:"-"`

// nolint
XXX_unrecognized []byte `json:"-"`

// nolint
XXX_sizecache int32 `json:"-"`

cachedValue interface{}
Expand Down
Loading