Skip to content

Commit

Permalink
problem: fix golangci-lint (#805)
Browse files Browse the repository at this point in the history
* use go 1.19

* fix nix-shell

* update golint config from cosmos-sdk

* upgrade golint action

* fix lint

Co-authored-by: HuangYi <[email protected]>
  • Loading branch information
JayT106 and yihuang authored Jan 9, 2023
1 parent e3bd4bf commit 6365729
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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
version: v1.50.0
args: --timeout 10m
github-token: ${{ secrets.GITHUB_TOKEN }}
# Check only if there are differences in the source code
Expand Down
81 changes: 32 additions & 49 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,66 @@
run:
tests: false
# timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
tests: true
timeout: 10m
sort-results: true
allow-parallel-runners: true
exclude-dir: testutil/testdata_pulsar
concurrency: 4

linters:
disable-all: true
enable:
# - bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- revive
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
# - lll TODO: enable
- misspell
- nakedret
- prealloc
- exportloopref
- nolintlint
- staticcheck
# - structcheck
- revive
- stylecheck
# - typecheck #TODO: enable
- typecheck
- unconvert
# - unparam
- unused
- varcheck
- nolintlint
- asciicheck
# - exhaustive
- exportloopref
- gofumpt
- gomodguard
# - nestif
# - nlreturn
# - noctx
# - rowserrcheck
# - whitespace
# - wsl

issues:
exclude-rules:
- path: _test\.go
- text: "Use of weak random number generator"
linters:
- gosec
- linters:
- lll
source: "https://"
max-same-issues: 50
- 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
golint:
min-confidence: 0
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
misspell:
locale: US
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
gofumpt:
lang-version: "1.18"
gomodguard:
blocked:
versions: # List of blocked module version constraints
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
3 changes: 2 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (app *App) ExportAppStateAndValidators(

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favor of export at a block height
//
// in favor of export at a block height
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

Expand Down
6 changes: 3 additions & 3 deletions app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"time"

sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -58,7 +58,7 @@ func StateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simtypes

case config.ParamsFile != "":
appParams := make(simtypes.AppParams)
bz, err := ioutil.ReadFile(config.ParamsFile)
bz, err := os.ReadFile(config.ParamsFile)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func StateRandomizedFn(
// StateFromGenesisFileFn util function to generate the genesis AppState
// from a genesis.json file.
func StateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) {
bytes, err := ioutil.ReadFile(genesisFile)
bytes, err := os.ReadFile(genesisFile)
if err != nil {
panic(err)
}
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

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

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
flake-utils.url = "github:numtide/flake-utils";
nix-bundle-exe = {
url = "github:3noch/nix-bundle-exe";
flake = false;
};
gomod2nix = {
url = "github:yihuang/gomod2nix";
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
Expand Down
4 changes: 2 additions & 2 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import sources.nixpkgs {
go-ethereum = pkgs.callPackage ./go-ethereum.nix {
inherit (pkgs.darwin) libobjc;
inherit (pkgs.darwin.apple_sdk.frameworks) IOKit;
buildGoModule = pkgs.buildGo117Module;
buildGoModule = pkgs.buildGo118Module;
};
flake-compat = import sources.flake-compat;
chain-maind = pkgs.callPackage sources.chain-main { };
Expand Down Expand Up @@ -59,7 +59,7 @@ import sources.nixpkgs {
});
})
(_: pkgs: {
cosmovisor = pkgs.buildGo117Module rec {
cosmovisor = pkgs.buildGo118Module rec {
name = "cosmovisor";
src = sources.cosmos-sdk + "/cosmovisor";
subPackages = [ "./cmd/cosmovisor" ];
Expand Down
16 changes: 8 additions & 8 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"branch": "master",
"description": "Convert applications using Go modules to Nix expressions",
"homepage": null,
"owner": "yihuang",
"owner": "nix-community",
"repo": "gomod2nix",
"rev": "598c5ab1a677eee3c799e09d23bab8cecb9b1e2f",
"sha256": "0vfb1fjrx8vfzqgrk39ilwxlb591kyz4c0dazai5cl6hbxjb0i2w",
"rev": "89cd0675b96775aa3ee86e7c0cf5bc238dd27976",
"sha256": "1x7w9ibp9nxzsaqg9lm6sav0438rwdh76r9pi40hikzn4nl9w4p0",
"type": "tarball",
"url": "https://github.com/yihuang/gomod2nix/archive/598c5ab1a677eee3c799e09d23bab8cecb9b1e2f.tar.gz",
"url": "https://github.com/nix-community/gomod2nix/archive/89cd0675b96775aa3ee86e7c0cf5bc238dd27976.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gravity-bridge": {
Expand Down Expand Up @@ -97,15 +97,15 @@
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "master",
"branch": "release-22.11",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ea2c6a6dda1aa35a80139a512a9dee375b0946e7",
"sha256": "0nd4nn9ryqa80ssw3j2kmr8wa73p2xz1hyxp280cdzqlmdfgw1lm",
"rev": "333feefeae8ecb703180c650f8071efb21cfd7ec",
"sha256": "0b5c5jsi0yd03z8hq2zrn7g0xpa7qjd7ayi924qxn9arvbxhfj25",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/ea2c6a6dda1aa35a80139a512a9dee375b0946e7.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/333feefeae8ecb703180c650f8071efb21cfd7ec.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"rocksdb": {
Expand Down
8 changes: 4 additions & 4 deletions x/cronos/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ $ %s tx gov submit-legacy-proposal token-mapping-change gravity0x0000...0000 0x0
return err
}

title, err := cmd.Flags().GetString(govcli.FlagTitle)
title, err := cmd.Flags().GetString(govcli.FlagTitle) //nolint:staticcheck
if err != nil {
return err
}

description, err := cmd.Flags().GetString(govcli.FlagDescription)
description, err := cmd.Flags().GetString(govcli.FlagDescription) //nolint:staticcheck
if err != nil {
return err
}
Expand Down Expand Up @@ -197,8 +197,8 @@ $ %s tx gov submit-legacy-proposal token-mapping-change gravity0x0000...0000 0x0
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(govcli.FlagTitle, "", "The proposal title")
cmd.Flags().String(govcli.FlagDescription, "", "The proposal description")
cmd.Flags().String(govcli.FlagTitle, "", "The proposal title") //nolint:staticcheck
cmd.Flags().String(govcli.FlagDescription, "", "The proposal description") //nolint:staticcheck
cmd.Flags().String(govcli.FlagDeposit, "", "The proposal deposit")
cmd.Flags().String(FlagSymbol, "", "The coin symbol")
cmd.Flags().Uint(FlagDecimals, 0, "The coin decimal")
Expand Down
5 changes: 2 additions & 3 deletions x/cronos/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
contract := common.BigToAddress(big.NewInt(1))
recipient := common.BigToAddress(big.NewInt(3))
sender := common.BigToAddress(big.NewInt(4))
denom := "testdenom"

testCases := []struct {
msg string
Expand Down Expand Up @@ -148,7 +147,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
"success send to evm chain",
func() {
suite.SetupTest()
denom := "gravity0x0000000000000000000000000000000000000000"
denom := denomGravity

suite.app.CronosKeeper.SetExternalContractForDenom(suite.ctx, denom, contract)
coin := sdk.NewCoin(denom, sdk.NewInt(100))
Expand Down Expand Up @@ -186,7 +185,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
balance = suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(contract.Bytes()), denom)
suite.Require().Equal(sdk.NewCoin(denom, sdk.NewInt(0)), balance)
// query unbatched SendToEthereum message exist
rsp, err := suite.app.GravityKeeper.UnbatchedSendToEthereums(sdk.WrapSDKContext(suite.ctx), &gravitytypes.UnbatchedSendToEthereumsRequest{
rsp, _ := suite.app.GravityKeeper.UnbatchedSendToEthereums(sdk.WrapSDKContext(suite.ctx), &gravitytypes.UnbatchedSendToEthereumsRequest{
SenderAddress: sdk.AccAddress(sender.Bytes()).String(),
})
suite.Require().Equal(1, len(rsp.SendToEthereums))
Expand Down
3 changes: 2 additions & 1 deletion x/cronos/keeper/evm_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package keeper_test

import (
"github.com/crypto-org-chain/cronos/x/cronos/types"
"math/big"

"github.com/crypto-org-chain/cronos/x/cronos/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
Expand Down
Loading

0 comments on commit 6365729

Please sign in to comment.