From 7af5d5625d0a6d87a639a40540535f306af66018 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 11:00:50 +0800 Subject: [PATCH 1/9] chg: upgrade golangci-lint --- .github/workflows/lint.yml | 13 ++++++------- .golangci.yaml | 7 ++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 506a2cf6..f6f8fc73 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,17 +2,16 @@ name: Lint Check on: [pull_request] jobs: - build: + golangci: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install Go - uses: actions/setup-go@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: 1.17 + go-version: '1.22' - name: "Run lint" - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: - version: v1.41 + version: v1.53.3 args: --timeout=10m only-new-issues: true \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml index 348669d1..c1855ff7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -16,9 +16,14 @@ linters: - cyclop - nestif - gocognit + - structcheck + - ifshort + - nosnakecase + - deadcode + - varcheck service: - golangci-lint-version: 1.41 + golangci-lint-version: 1.53.3 run: skip-dirs: From a4c4d85e2d3f9b5ba74fdfb1d7758d672e0ef38c Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 11:23:49 +0800 Subject: [PATCH 2/9] add: invalid case --- bridge/setu/util/common.go | 20 +++++++++++++++++--- cmd/deliveryd/main.go | 5 +++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bridge/setu/util/common.go b/bridge/setu/util/common.go index b3fd47e7..d96189a4 100644 --- a/bridge/setu/util/common.go +++ b/bridge/setu/util/common.go @@ -83,19 +83,32 @@ var ( loggerOnce sync.Once ) +func invalidCases() { + x := 30 * time.Second + _ = x * time.Second // want `Multiplication of durations` +} + // Logger returns logger singleton instance func Logger() log.Logger { + var test = 1 + var test2 = 1 + var test3 = "aPI" + var test4, err2 = time.Parse("sss", "12333") + fmt.Printf("%d") loggerOnce.Do(func() { + test2 = 1 defaultLevel := "info" logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) option, err := log.AllowLevel(viper.GetString("log_level")) + test2 = 1 if err != nil { + test2 = 1 // cosmos sdk is using different style of log format // and levels don't map well, config.toml // see: https://github.com/cosmos/cosmos-sdk/pull/8072 - logger.Error("Unable to parse logging level", "Error", err) + logger.Error("Unable to parse logging level ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccijodjoijfodsjfospjpfsccccc", "Error", err) logger.Info("Using default log level") - + logger.Info("Using default log level", "aPI", test, "test2", test2, "test3", test3, test4, err2) option, err = log.AllowLevel(defaultLevel) if err != nil { logger.Error("failed to allow default log level", "Level", defaultLevel, "Error", err) @@ -107,8 +120,9 @@ func Logger() log.Logger { if viper.GetString("log_level") != "debug" { mLog.SetDebug(NoopLogger{}) } + test2 = 1 }) - + test2 = 1 return logger } diff --git a/cmd/deliveryd/main.go b/cmd/deliveryd/main.go index d2d8c46f..223c8b1a 100644 --- a/cmd/deliveryd/main.go +++ b/cmd/deliveryd/main.go @@ -191,6 +191,11 @@ func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io. return bapp.ExportAppStateAndValidators() } +func InvalidCases() { + x := 30 * time.Second + _ = x * time.Second // want `Multiplication of durations` +} + func deliveryStart(shutdownCtx context.Context, ctx *server.Context, appCreator server.AppCreator, cdc *codec.Codec, ) *cobra.Command { From 19cc1d0b5296dfab7ba92e15e38bbee6c6313df4 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 11:27:00 +0800 Subject: [PATCH 3/9] add: invalid case --- cmd/deliveryd/main.go | 59 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/cmd/deliveryd/main.go b/cmd/deliveryd/main.go index 223c8b1a..7f2f8fec 100644 --- a/cmd/deliveryd/main.go +++ b/cmd/deliveryd/main.go @@ -191,9 +191,66 @@ func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io. return bapp.ExportAppStateAndValidators() } -func InvalidCases() { +const ( + timeout = 10 * time.Second + foo = 10 +) + +type myStruct struct { + fieldA int + fieldB time.Duration + fieldC *int +} + +func invalidCases() { x := 30 * time.Second + ms := myStruct{fieldA: 10, fieldB: 10 * time.Second} + tdArr := []time.Duration{1} + _ = x * time.Second // want `Multiplication of durations` + + _ = time.Second * x // want `Multiplication of durations` + + _ = timeout * time.Millisecond // want `Multiplication of durations` + + _ = someDuration() * time.Second // want `Multiplication of durations` + + _ = time.Millisecond * someDuration() // want `Multiplication of durations` + + _ = *somePointerDuration() * time.Second // want `Multiplication of durations` + + _ = time.Millisecond * *somePointerDuration() // want `Multiplication of durations` + + _ = (30 * time.Second) * time.Millisecond // want `Multiplication of durations` + + _ = time.Millisecond * (30 * time.Second) // want `Multiplication of durations` + + _ = time.Millisecond * time.Second * 1 // want `Multiplication of durations` + + _ = 1 * time.Second * (time.Second) // want `Multiplication of durations` + + _ = ms.fieldB * time.Second // want `Multiplication of durations` + + _ = time.Second * ms.fieldB // want `Multiplication of durations` + + _ = time.Duration(tdArr[0]) * time.Second // want `Multiplication of durations` +} +func someDuration() time.Duration { + return 10 * time.Second +} + +func someDurationMillis() int { + return 10 +} + +func somePointerDuration() *time.Duration { + v := 10 * time.Second + return &v +} + +func somePointerDurationMillis() *int { + v := 10 + return &v } func deliveryStart(shutdownCtx context.Context, From a6a200afad46c20aed774776271aaf1dcbef067b Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 16:29:22 +0800 Subject: [PATCH 4/9] add: invalid case --- cmd/deliveryd/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/deliveryd/main.go b/cmd/deliveryd/main.go index 7f2f8fec..a5712045 100644 --- a/cmd/deliveryd/main.go +++ b/cmd/deliveryd/main.go @@ -61,6 +61,7 @@ var ( flagOutputDir = "output-dir" flagNodeDaemonHome = "node-daemon-home" flagNodeHostPrefix = "node-host-prefix" + testnoUse = "xx" ) // Tendermint full-node start flags. @@ -72,6 +73,7 @@ const ( FlagMinGasPrices = "minimum-gas-prices" FlagHaltHeight = "halt-height" FlagHaltTime = "halt-time" + FlagNoUse = "noUse" ) // nolint From f4ab955a6b53ddc25f4d2ff29cd7e931f27c6d51 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 16:30:33 +0800 Subject: [PATCH 5/9] add: invalid case --- cmd/deliveryd/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/deliveryd/main.go b/cmd/deliveryd/main.go index a5712045..7e15cc11 100644 --- a/cmd/deliveryd/main.go +++ b/cmd/deliveryd/main.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "math/big" + "net" "os" "os/signal" "path/filepath" From 38a58916a4513034af1e2bfa8c9cb09bbaf14a41 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 16:38:17 +0800 Subject: [PATCH 6/9] chg: upgrade lint to 1.58.0 --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f6f8fc73..2c777a3a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,6 +12,6 @@ jobs: - name: "Run lint" uses: golangci/golangci-lint-action@v6 with: - version: v1.53.3 + version: v1.58.0 args: --timeout=10m only-new-issues: true \ No newline at end of file From 861843358ab795fc087234e76217711060e29c0e Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 16:47:11 +0800 Subject: [PATCH 7/9] chg: disable check-annotations --- .golangci.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index c1855ff7..4f99067d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -41,4 +41,6 @@ issues: linters-settings: errcheck: check-type-assertions: true - check-blank: false \ No newline at end of file + check-blank: false + gosimple: + check-annotations: false \ No newline at end of file From 4786c8ab4a95bc54f90218001b769ef6d4c7f444 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 17:07:29 +0800 Subject: [PATCH 8/9] chg: disable Unchanged files with check annotations --- .github/workflows/lint.yml | 2 +- .golangci.yaml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2c777a3a..d758eb2d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,7 +8,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.22' + go-version: '1.21' - name: "Run lint" uses: golangci/golangci-lint-action@v6 with: diff --git a/.golangci.yaml b/.golangci.yaml index 4f99067d..c1855ff7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -41,6 +41,4 @@ issues: linters-settings: errcheck: check-type-assertions: true - check-blank: false - gosimple: - check-annotations: false \ No newline at end of file + check-blank: false \ No newline at end of file From 8fa8604f1d04e88c752eaa99b417b846af1d1527 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Tue, 7 May 2024 17:26:12 +0800 Subject: [PATCH 9/9] chg: update lint --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d758eb2d..07da4229 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,10 +8,10 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: "Run lint" uses: golangci/golangci-lint-action@v6 with: - version: v1.58.0 + version: v1.57.2 args: --timeout=10m only-new-issues: true \ No newline at end of file