diff --git a/.golangci.yml b/.golangci.yml index 488a4851ac..b3fe2395a8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,38 +1,4 @@ run: -<<<<<<< HEAD - tests: false -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m - -linters: - disable-all: false - enable: - - gofmt - - goconst - - goimports - - gosec - - gosimple - - govet - - ineffassign - - misspell - - nakedret - - prealloc - - staticcheck - - stylecheck - - typecheck - - unconvert - - unused - - unparam - - misspell - disable: - - gocritic - - errcheck - - interfacer - - wsl - - nolintlint - -issues: -======= tests: true timeout: 15m allow-parallel-runners: true @@ -88,7 +54,6 @@ issues: - ".*\\.pb\\.gw\\.go$" - ".*\\.pulsar\\.go$" - crypto/keys/secp256k1/internal/* ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) exclude-rules: - text: "Use of weak random number generator" linters: @@ -112,17 +77,105 @@ issues: text: "SA1019: token." linters: - staticcheck + - path: "legacy" + text: "SA1019:" + linters: + - staticcheck + - text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out + linters: + - staticcheck + - text: "SA1019: legacybech32.MustMarshalPubKey" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: legacybech32.MarshalPubKey" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: legacybech32.UnmarshalPubKey" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: \"github.com/golang/protobuf/proto\" is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: vote.Option is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "SA1019: types.QueryNextAccountNumberRequest is deprecated" # TODO remove once ready to remove from the sdk + linters: + - staticcheck + - text: "leading space" + linters: + - nolintlint + - path: _test\.go + linters: + - goconst max-issues-per-linter: 10000 max-same-issues: 10000 linters-settings: + gci: + custom-order: true + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/Finschia/finschia-sdk) + revive: + rules: + - name: redefines-builtin-id + disabled: true + + gosec: + includes: + # - G101 # Look for hard coded credentials + - G102 # Bind to all interfaces + - G103 # Audit the use of unsafe block + - G104 # Audit errors not checked + - G106 # Audit the use of ssh.InsecureIgnoreHostKey + - G107 # Url provided to HTTP request as taint input + - G108 # Profiling endpoint automatically exposed on /debug/pprof + - G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32 + - G110 # Potential DoS vulnerability via decompression bomb + - G111 # Potential directory traversal + - G112 # Potential slowloris attack + - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772) + - G114 # Use of net/http serve function that has no support for setting timeouts + - G201 # SQL query construction using format string + - G202 # SQL query construction using string concatenation + - G203 # Use of unescaped data in HTML templates + - G204 # Audit use of command execution + - G301 # Poor file permissions used when creating a directory + - G302 # Poor file permissions used with chmod + - G303 # Creating tempfile using a predictable path + - G304 # File path provided as taint input + - G305 # File traversal when extracting zip/tar archive + - G306 # Poor file permissions used when writing to a new file + - G307 # Deferring a method which returns an error + - G401 # Detect the usage of DES, RC4, MD5 or SHA1 + - G402 # Look for bad TLS connection settings + - G403 # Ensure minimum RSA key length of 2048 bits + - G404 # Insecure random number source (rand) + - G501 # Import blocklist: crypto/md5 + - G502 # Import blocklist: crypto/des + - G503 # Import blocklist: crypto/rc4 + - G504 # Import blocklist: net/http/cgi + - G505 # Import blocklist: crypto/sha1 + - G601 # Implicit memory aliasing of items from a range statement + misspell: + locale: US + gofumpt: + extra-rules: true dogsled: -<<<<<<< HEAD - max-blank-identifiers: 3 -======= max-blank-identifiers: 6 ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) nolintlint: allow-unused: false require-explanation: false - require-specific: false \ No newline at end of file + require-specific: false + gosimple: + checks: ["all"] + gocritic: + disabled-checks: + - regexpMust + - appendAssign + - ifElseChain \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5248d414d7..6ebb44697c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,39 +42,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (x/fswap) [\#1415](https://github.com/Finschia/finschia-sdk/pull/1415) add more testcases for fswap module - +* (style) [\#1426](https://github.com/Finschia/finschia-sdk/pull/1426) Improve code quality with new linters + ### Bug Fixes -<<<<<<< HEAD -======= -* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue -* (x/auth, x/slashing) [\#1179](https://github.com/Finschia/finschia-sdk/pull/1179) modify missing changes of converting to tendermint -* (x/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. -* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis -* (x/foundation) [\#1277](https://github.com/Finschia/finschia-sdk/pull/1277) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic -* (x/collection, x/token) [\#1288](https://github.com/Finschia/finschia-sdk/pull/1288) use accAddress to compare in validatebasic function in collection & token modules -* (x/collection) [\#1268](https://github.com/Finschia/finschia-sdk/pull/1268) export x/collection params into genesis -* (x/collection) [\#1294](https://github.com/Finschia/finschia-sdk/pull/1294) reject NFT coins on FT APIs -* (sec) [\#1302](https://github.com/Finschia/finschia-sdk/pull/1302) remove map iteration non-determinism with keys + sorting -* (client) [\#1303](https://github.com/Finschia/finschia-sdk/pull/1303) fix possible overflow in BuildUnsignedTx -* (types) [\#1299](https://github.com/Finschia/finschia-sdk/pull/1299) add missing nil checks -* (x/staking) [\#1301](https://github.com/Finschia/finschia-sdk/pull/1301) Use bytes instead of string comparison in delete validator queue (backport cosmos/cosmos-sdk#12303) -* (x/gov) [\#1304](https://github.com/Finschia/finschia-sdk/pull/1304) fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query -* (x/staking) [\#1306](https://github.com/Finschia/finschia-sdk/pull/1306) add validation for potential slashing evasion during re-delegation -* (client/keys) [#1312](https://github.com/Finschia/finschia-sdk/pull/1312) ignore error when key not found in `keys delete` -* (store) [\#1310](https://github.com/Finschia/finschia-sdk/pull/1310) fix app-hash mismatch if upgrade migration commit is interrupted(backport cosmos/cosmos-sdk#13530) -* (types) [\#1313](https://github.com/Finschia/finschia-sdk/pull/1313) fix correctly coalesce coins even with repeated denominations(backport cosmos/cosmos-sdk#13265) -* (x/crypto) [\#1316](https://github.com/Finschia/finschia-sdk/pull/1316) error if incorrect ledger public key (backport cosmos/cosmos-sdk#14460, cosmos/cosmos-sdk#19691) -* (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig -* (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation -* (x/server) [\#1337](https://github.com/Finschia/finschia-sdk/pull/1337) fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter (backport cosmos/cosmos-sdk#18537) -* (x/fbridge) [\#1361](https://github.com/Finschia/finschia-sdk/pull/1361) Fixes fbridge auth checking bug -* (x/fswap) [\#1365](https://github.com/Finschia/finschia-sdk/pull/1365) fix update swap keys for possibly overlapped keys(`(hello,world) should be different to (hel,loworld)`) -* (x/fswap, x/fbridge) [\#1378](https://github.com/Finschia/finschia-sdk/pull/1378) Fix bug where amino is not supported in fswap and fbridge -* (x/fswap) [\#1379](https://github.com/Finschia/finschia-sdk/pull/1379) add missing router registration -* (x/fswap) [\#1385](https://github.com/Finschia/finschia-sdk/pull/1385) add accidentally deleted event emissions(EventSetSwap, EventAddDenomMetadata) -* (x/fswap) [\#1392](https://github.com/Finschia/finschia-sdk/pull/1392) fix dummy denom coin data for test in fswap -* (style) [\#1414](https://github.com/Finschia/finschia-sdk/pull/1414) improve code quality with new linters ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) ### Removed @@ -88,4 +58,5 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Build, CI * (build, ci) [\#1410](https://github.com/Finschia/finschia-sdk/pull/1410) Bump Go from 1.20 to 1.22 * (build) [\#1413](https://github.com/Finschia/finschia-sdk/pull/1413) Update outdated dependencies for v0.49.x + ### Document Updates diff --git a/Makefile b/Makefile index 7bb1376fa7..8d8539b4a7 100644 --- a/Makefile +++ b/Makefile @@ -354,11 +354,7 @@ lint: golangci-lint find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -d -s golangci-lint: -<<<<<<< HEAD - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 -======= @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) lint-fix: golangci-lint golangci-lint run --fix --out-format=tab --issues-exit-code=0 diff --git a/server/oc_cmds_test.go b/server/oc_cmds_test.go index 742233e4ec..5d05eb7ab2 100644 --- a/server/oc_cmds_test.go +++ b/server/oc_cmds_test.go @@ -3,7 +3,6 @@ package server import ( "bytes" "context" - "errors" "fmt" "io/ioutil" "os" @@ -33,11 +32,7 @@ func TestShowValidator(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD:server/oc_cmds_test.go if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)):server/tm_cmds_test.go t.Fatalf("function failed with [%T] %v", err, err) } @@ -58,11 +53,7 @@ func TestShowValidatorWithKMS(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD:server/oc_cmds_test.go if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)):server/tm_cmds_test.go t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/server/util_test.go b/server/util_test.go index a271591de3..7899c7947f 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -39,11 +39,7 @@ func TestInterceptConfigsPreRunHandlerCreatesConfigFilesWhenMissing(t *testing.T serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -120,11 +116,7 @@ func TestInterceptConfigsPreRunHandlerReadsConfigToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -161,11 +153,7 @@ func TestInterceptConfigsPreRunHandlerReadsAppToml(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -193,11 +181,7 @@ func TestInterceptConfigsPreRunHandlerReadsFlags(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -222,17 +206,17 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) { basename = strings.ReplaceAll(basename, ".", "_") // This is added by ostracon envVarName := fmt.Sprintf("%s_RPC_LADDR", strings.ToUpper(basename)) - t.Setenv(envVarName, testAddr) + os.Setenv(envVarName, testAddr) + t.Cleanup(func() { + os.Unsetenv(envVarName) + }) + cmd.PreRunE = preRunETestImpl serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -336,11 +320,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceFlag(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -356,11 +336,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceEnvVar(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -376,11 +352,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigFile(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } @@ -396,11 +368,7 @@ func TestInterceptConfigsPreRunHandlerPrecedenceConfigDefault(t *testing.T) { serverCtx := &Context{} ctx := context.WithValue(context.Background(), ServerContextKey, serverCtx) -<<<<<<< HEAD if err := testCommon.cmd.ExecuteContext(ctx); err != cancelledInPreRun { -======= - if err := testCommon.cmd.ExecuteContext(ctx); !errors.Is(err, errCancelledInPreRun) { ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) t.Fatalf("function failed with [%T] %v", err, err) } diff --git a/x/foundation/client/testutil/tx.go b/x/foundation/client/testutil/tx.go index f352b9c1a8..36f7169dc6 100644 --- a/x/foundation/client/testutil/tx.go +++ b/x/foundation/client/testutil/tx.go @@ -44,6 +44,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdFundTreasury() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdFundTreasury() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -90,6 +92,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdWithdrawFromTreasury() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdWithdrawFromTreasury() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -134,6 +138,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdUpdateMembers() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdUpdateMembers() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -192,6 +198,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdUpdateDecisionPolicy() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdUpdateDecisionPolicy() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -241,6 +249,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdSubmitProposal() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdSubmitProposal() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -289,6 +299,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdWithdrawProposal() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdWithdrawProposal() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -341,6 +353,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdVote() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdVote() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -388,6 +402,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdExec() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdExec() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -404,70 +420,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdExec() { } } -<<<<<<< HEAD -======= -func (s *IntegrationTestSuite) TestNewTxCmdUpdateCensorship() { - val := s.network.Validators[0] - commonArgs := []string{ - fmt.Sprintf("--%s", flags.FlagGenerateOnly), - } - - testCases := map[string]struct { - args []string - valid bool - }{ - "valid transaction": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - foundation.CensorshipAuthorityGovernance.String(), - }, - true, - }, - "valid abbreviation": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - "governance", - }, - true, - }, - "wrong number of args": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - foundation.CensorshipAuthorityGovernance.String(), - "extra", - }, - false, - }, - "invalid new authority": { - []string{ - s.authority.String(), - foundation.ReceiveFromTreasuryAuthorization{}.MsgTypeURL(), - "invalid-new-authority", - }, - false, - }, - } - - for name, tc := range testCases { - s.Run(name, func() { - cmd := cli.NewTxCmdUpdateCensorship() - out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) - if !tc.valid { - s.Require().Error(err) - return - } - s.Require().NoError(err) - - var res txtypes.Tx - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out) - }) - } -} - ->>>>>>> d60e44aa6 (style: Improve code quality with new linters (#1414)) func (s *IntegrationTestSuite) TestNewTxCmdLeaveFoundation() { val := s.network.Validators[0] commonArgs := []string{ @@ -497,6 +449,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdLeaveFoundation() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdLeaveFoundation() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -548,6 +502,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdGrant() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdGrant() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) @@ -593,6 +549,8 @@ func (s *IntegrationTestSuite) TestNewTxCmdRevoke() { } for name, tc := range testCases { + tc := tc + s.Run(name, func() { cmd := cli.NewTxCmdRevoke() out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))