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

[sdk50] Lint the go relayer like IBC-go #1274

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 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
55 changes: 55 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: golangci-lint
on:
push:
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: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
151 changes: 110 additions & 41 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,130 @@
run:
tests: true
allow-parallel-runners: true
# # timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m
skip-files:
- relayer/codecs/injective/tx.pb.go

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
# - errcheck
# - funlen
# - gochecknoglobals
# - gochecknoinits
- exportloopref
- errcheck
- gci
- goconst
- gocritic
# - gocyclo
# - godox
- gofmt
- goimports
- golint
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
# - maligned
- nakedret
- prealloc
- scopelint
- staticcheck
- structcheck
- thelper
- typecheck
- stylecheck
- revive
- typecheck
- tenv
- unconvert
# - unparam
# Prefer unparam over revive's unused param. It is more thorough in its checking.
- unparam
- unused
- varcheck
# - whitespace
# - wsl
# - gocognit
- nolintlint
- misspell

issues:
exclude-rules:
- linters:
- lll
source: "https://"
max-same-issues: 50
- text: 'differs only by capitalization to method'
linters:
- revive
- text: 'Use of weak random number generator'
linters:
- gosec
- text: 'ST1003'
linters:
- stylecheck

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

linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
suggest-new: true
# govet:
# check-shadowing: true
golint:
min-confidence: 0
# gocyclo:
# min-complexity: 10
# misspell:
# locale: US
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cometbft/cometbft)
- prefix(github.com/cosmos/relayer)
custom-order: true
revive:
enable-all-rules: true
# Do NOT whine about the following, full explanation found in:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#description-of-available-rules
rules:
- name: import-shadowing
disabled: true
- name: exported
disabled: true
- name: use-any
disabled: true
- name: if-return
disabled: true
- name: max-public-structs
disabled: true
- name: cognitive-complexity
disabled: true
- name: argument-limit
disabled: true
- name: cyclomatic
disabled: true
- name: file-header
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: flag-parameter
disabled: true
- name: add-constant
disabled: true
- name: empty-lines
disabled: true
- name: banned-characters
disabled: true
- name: deep-exit
disabled: true
- name: confusing-results
disabled: true
- name: unused-parameter
disabled: true
- name: modifies-value-receiver
disabled: true
- name: early-return
disabled: true
- name: confusing-naming
disabled: true
- name: var-naming
disabled: true
- name: defer
disabled: true
# Disabled in favour of unparam.
- name: unused-parameter
disabled: true
- name: unhandled-error
disabled: true
arguments:
- 'fmt.Printf'
- 'fmt.Print'
- 'fmt.Println'
- 'myFunction'
- name: nested-structs
disabled: true
- name: context-as-argument
disabled: true
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DIRTY := $(shell git status --porcelain | wc -l | xargs)
GAIA_VERSION := v7.0.1
AKASH_VERSION := v0.16.3
OSMOSIS_VERSION := v8.0.0
WASMD_VERSION := v0.25.0
WASMD_VERSION := v0.41.0
DOCKER := $(shell which docker)

GOPATH := $(shell go env GOPATH)
Expand Down Expand Up @@ -165,7 +165,7 @@ release:
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist

protoVer=0.11.2
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

Expand Down
5 changes: 3 additions & 2 deletions cmd/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"os"
"path"

"github.com/cosmos/relayer/v2/relayer"
"github.com/gofrs/flock"
"github.com/spf13/viper"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

"github.com/cosmos/relayer/v2/relayer"
)

// appState is the modifiable state of the application.
Expand Down Expand Up @@ -212,7 +213,7 @@ func (a *appState) performConfigLockingOperation(ctx context.Context, operation
cfgPath := a.configPath()

// Overwrite the config file.
if err := os.WriteFile(cfgPath, out, 0600); err != nil {
if err := os.WriteFile(cfgPath, out, 0o600); err != nil {
return fmt.Errorf("failed to write config file at %s: %w", cfgPath, err)
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
"path/filepath"
"strings"

"github.com/cosmos/relayer/v2/cregistry"
"github.com/cosmos/relayer/v2/relayer"
"github.com/cosmos/relayer/v2/relayer/provider"
"github.com/spf13/cobra"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

"github.com/cosmos/relayer/v2/cregistry"
"github.com/cosmos/relayer/v2/relayer"
"github.com/cosmos/relayer/v2/relayer/provider"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions cmd/chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"regexp"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/relayer/v2/cmd"
"github.com/cosmos/relayer/v2/internal/relayertest"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
"github.com/stretchr/testify/require"
)

func TestChainsList_Empty(t *testing.T) {
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestChainsAdd_URL(t *testing.T) {
}

enc := json.NewEncoder(w)
enc.Encode(pcw)
enc.Encode(pcw) // nolint:errcheck // we don't care about the error here
})
srv := httptest.NewServer(h)
defer srv.Close()
Expand Down
20 changes: 10 additions & 10 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"reflect"
"strings"
"time"

"github.com/spf13/cobra"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

"github.com/cosmos/relayer/v2/relayer"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
"github.com/cosmos/relayer/v2/relayer/chains/penumbra"
"github.com/cosmos/relayer/v2/relayer/provider"
"github.com/spf13/cobra"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
)

func configCmd(a *appState) *cobra.Command {
Expand Down Expand Up @@ -179,7 +179,7 @@ $ %s cfg i`, appName, defaultHome, appName)),
// An error is only returned if the directory cannot be read at all.
func addChainsFromDirectory(ctx context.Context, stderr io.Writer, a *appState, dir string) error {
dir = path.Clean(dir)
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return err
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func addChainsFromDirectory(ctx context.Context, stderr io.Writer, a *appState,
// which means a's paths may include a subset of the path files in dir.
func addPathsFromDirectory(ctx context.Context, stderr io.Writer, a *appState, dir string) error {
dir = path.Clean(dir)
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return err
}
Expand Down Expand Up @@ -395,8 +395,8 @@ func UnmarshalJSONProviderConfig(data []byte, customTypes map[string]reflect.Typ
}

typeName, ok := m["type"].(string)
if !ok {
return nil, errors.New("cannot find type");
if !ok {
return nil, errors.New("cannot find type")
}

var provCfg provider.ProviderConfig
Expand Down Expand Up @@ -648,7 +648,7 @@ func (c *Config) ValidatePathEnd(ctx context.Context, stderr io.Writer, pe *rela
}

// ValidateClient validates client id in provided pathend
func (c *Config) ValidateClient(ctx context.Context, chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
func (*Config) ValidateClient(ctx context.Context, chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
if err := pe.Vclient(); err != nil {
return err
}
Expand All @@ -662,7 +662,7 @@ func (c *Config) ValidateClient(ctx context.Context, chain *relayer.Chain, heigh
}

// ValidateConnection validates connection id in provided pathend
func (c *Config) ValidateConnection(ctx context.Context, chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
func (*Config) ValidateConnection(ctx context.Context, chain *relayer.Chain, height int64, pe *relayer.PathEnd) error {
if err := pe.Vconn(); err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ func errChainNotFound(chainName string) error {
return fmt.Errorf("chain with name \"%s\" not found in config. consider running `rly chains add %s`", chainName, chainName)
}

var (
errMultipleAddFlags = errors.New("expected either --file/-f OR --url/u, found multiple")
)
var errMultipleAddFlags = errors.New("expected either --file/-f OR --url/u, found multiple")
Loading
Loading