This is an automated email from the ASF dual-hosted git repository.

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new ae6ace22a ci: introduce `revive` as the linter replacement for 
`golint` (#2247)
ae6ace22a is described below

commit ae6ace22a445702c429fb56906f9e65493e4fd04
Author: Dan Wang <[email protected]>
AuthorDate: Wed May 14 10:50:47 2025 +0800

    ci: introduce `revive` as the linter replacement for `golint` (#2247)
    
    [golint](https://github.com/golang/lint) has been deprecated (since 
v1.41.0) and
    archived by the owner. [Golangci-lint](https://golangci-lint.run) recommends
    [revive](https://github.com/mgechev/revive), a drop-in replacement of golint
    and used by many well-known projects such as `tidb` and `etcd`.
    
    Therefore we introduce `revive` as the linter for all workflows for Go, 
including
    `go-client`, `collector`, `admin-cli` and `pegic`. The problems found by 
`revive`
    are also fixed according to the warnings.
---
 .github/workflows/lint_and_test_admin-cli.yml |  1 +
 .github/workflows/lint_and_test_collector.yml |  1 +
 .github/workflows/lint_and_test_pegic.yml     |  1 +
 .golangci.yml                                 | 13 +++++++++-
 admin-cli/client/fake_meta_test.go            | 36 +++++++++++++--------------
 admin-cli/client/meta.go                      | 12 ++++-----
 admin-cli/executor/server_config.go           |  4 +--
 admin-cli/executor/table_version.go           | 13 +++++-----
 admin-cli/tabular/template.go                 |  2 +-
 admin-cli/util/common_utils.go                | 14 ++++++++---
 collector/avail/detector.go                   |  6 ++---
 collector/metrics/metric_collector.go         |  2 +-
 collector/usage/usage_recorder.go             |  2 +-
 go-client/.golangci.yml                       | 14 +++++++++++
 go-client/admin/client_test.go                |  6 ++---
 pegic/interactive/cmd/compression.go          |  2 +-
 pegic/interactive/cmd/encoding.go             |  2 +-
 pegic/shell/app.go                            |  4 +--
 18 files changed, 85 insertions(+), 50 deletions(-)

diff --git a/.github/workflows/lint_and_test_admin-cli.yml 
b/.github/workflows/lint_and_test_admin-cli.yml
index f17f141e2..2b99a9a58 100644
--- a/.github/workflows/lint_and_test_admin-cli.yml
+++ b/.github/workflows/lint_and_test_admin-cli.yml
@@ -30,6 +30,7 @@ on:
       - '*dev'
     paths:
       - .github/workflows/lint_and_test_admin-cli.yml
+      - .golangci.yml
       - admin-cli/**
 
   # for manually triggering workflow
diff --git a/.github/workflows/lint_and_test_collector.yml 
b/.github/workflows/lint_and_test_collector.yml
index 46e473098..62ebd3cd4 100644
--- a/.github/workflows/lint_and_test_collector.yml
+++ b/.github/workflows/lint_and_test_collector.yml
@@ -30,6 +30,7 @@ on:
       - '*dev'
     paths:
       - .github/workflows/lint_and_test_collector.yml
+      - .golangci.yml
       - collector/**
       - go-client/**
 
diff --git a/.github/workflows/lint_and_test_pegic.yml 
b/.github/workflows/lint_and_test_pegic.yml
index 3cff3c1c5..ece668156 100644
--- a/.github/workflows/lint_and_test_pegic.yml
+++ b/.github/workflows/lint_and_test_pegic.yml
@@ -30,6 +30,7 @@ on:
       - '*dev'
     paths:
       - .github/workflows/lint_and_test_pegic.yml
+      - .golangci.yml
       - pegic/**
 
   # for manually triggering workflow
diff --git a/.golangci.yml b/.golangci.yml
index 013f1cd61..c73d5cc26 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -27,12 +27,23 @@ linters:
   enable:
     - gofmt
     - goimports
-    - golint
+    - revive
     - bodyclose
     - exhaustive
     - exportloopref
 
 linters-settings:
+  revive:
+    rules:
+      # 
https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#var-naming
+      - name: var-naming
+        severity: warning
+        disabled: false
+        exclude: [""]
+        arguments:
+          - ["ID", "RPC"] # AllowList
+          - [] # DenyList
+          - - upperCaseConst: true # Extra parameter 
(upper-case-const|skip-package-name-checks)
   exhaustive:
     # indicates that switch statements are to be considered exhaustive if a
     # 'default' case is present, even if all enum members aren't listed in the
diff --git a/admin-cli/client/fake_meta_test.go 
b/admin-cli/client/fake_meta_test.go
index c5d10dfc5..13406ac5c 100644
--- a/admin-cli/client/fake_meta_test.go
+++ b/admin-cli/client/fake_meta_test.go
@@ -167,7 +167,7 @@ func (m *fakeMeta) Balance(pid *base.Gpid, opType 
BalanceType, from *util.Pegasu
        return nil
 }
 
-func (m *fakeMeta) Propose(pid *base.Gpid, opType admin.ConfigType, target 
*util.PegasusNode, node *util.PegasusNode) error {
+func (m *fakeMeta) Propose(pid *base.Gpid, opType admin.ConfigType, _ 
*util.PegasusNode, node *util.PegasusNode) error {
        fakeNode := findNodeInFakeCluster(node)
 
        switch opType {
@@ -193,67 +193,67 @@ func findNodeInFakeCluster(pn *util.PegasusNode) 
*fakeNode {
        return ret
 }
 
-func (m *fakeMeta) StartBackupApp(tableID int, providerType string, backupPath 
string) (*admin.StartBackupAppResponse, error) {
+func (m *fakeMeta) StartBackupApp(_ int, _ string, _ string) 
(*admin.StartBackupAppResponse, error) {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) QueryBackupStatus(tableID int, backupID int64) 
(*admin.QueryBackupStatusResponse, error) {
+func (m *fakeMeta) QueryBackupStatus(_ int, _ int64) 
(*admin.QueryBackupStatusResponse, error) {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) RestoreApp(oldClusterName string, oldTableName string, 
oldTableID int, backupID int64, providerType string,
-       newTableName string, restorePath string, skipBadPartition bool, 
policyName string) (*admin.CreateAppResponse, error) {
+func (m *fakeMeta) RestoreApp(_ string, _ string, _ int, _ int64, _ string,
+       _ string, _ string, _ bool, _ string) (*admin.CreateAppResponse, error) 
{
        panic("unimplemented")
 }
 
-func (m *fakeMeta) StartPartitionSplit(tableName string, newPartitionCount 
int) error {
+func (m *fakeMeta) StartPartitionSplit(_ string, _ int) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) QuerySplitStatus(tableName string) 
(*admin.QuerySplitResponse, error) {
+func (m *fakeMeta) QuerySplitStatus(_ string) (*admin.QuerySplitResponse, 
error) {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) PausePartitionSplit(tableName string, parentPidx int) error 
{
+func (m *fakeMeta) PausePartitionSplit(_ string, _ int) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) RestartPartitionSplit(tableName string, parentPidx int) 
error {
+func (m *fakeMeta) RestartPartitionSplit(_ string, _ int) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) CancelPartitionSplit(tableName string, oldPartitionCount 
int) error {
+func (m *fakeMeta) CancelPartitionSplit(_ string, _ int) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) StartBulkLoad(tableName string, clusterName string, 
providerType string, rootPath string) error {
+func (m *fakeMeta) StartBulkLoad(_ string, _ string, _ string, _ string) error 
{
        panic("unimplemented")
 }
 
-func (m *fakeMeta) QueryBulkLoad(tableName string) 
(*admin.QueryBulkLoadResponse, error) {
+func (m *fakeMeta) QueryBulkLoad(_ string) (*admin.QueryBulkLoadResponse, 
error) {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) PauseBulkLoad(tableName string) error {
+func (m *fakeMeta) PauseBulkLoad(_ string) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) RestartBulkLoad(tableName string) error {
+func (m *fakeMeta) RestartBulkLoad(_ string) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) CancelBulkLoad(tableName string, forced bool) error {
+func (m *fakeMeta) CancelBulkLoad(_ string, _ bool) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) ClearBulkLoad(tableName string) error {
+func (m *fakeMeta) ClearBulkLoad(_ string) error {
        panic("unimplemented")
 }
 
-func (m *fakeMeta) StartManualCompaction(tableName string, targetLevel int, 
maxRunningCount int, bottommost bool) error {
+func (m *fakeMeta) StartManualCompaction(_ string, _ int, _ int, _ bool) error 
{
        panic("unimplemented")
 }
 
-func (m *fakeMeta) QueryManualCompaction(tableName string) 
(*admin.QueryAppManualCompactResponse, error) {
+func (m *fakeMeta) QueryManualCompaction(_ string) 
(*admin.QueryAppManualCompactResponse, error) {
        panic("unimplemented")
 }
diff --git a/admin-cli/client/meta.go b/admin-cli/client/meta.go
index e4b680f13..e9b965e9b 100644
--- a/admin-cli/client/meta.go
+++ b/admin-cli/client/meta.go
@@ -302,7 +302,7 @@ func (m *rpcBasedMeta) DropApp(tableName string, 
reserveSeconds int64) error {
                        ReserveSeconds:    &reserveSeconds,
                },
        }
-       err := m.callMeta("DropApp", req, func(resp interface{}) {})
+       err := m.callMeta("DropApp", req, func(_ interface{}) {})
        return err
 }
 
@@ -312,7 +312,7 @@ func (m *rpcBasedMeta) ModifyDuplication(tableName string, 
dupid int, status adm
                Dupid:   int32(dupid),
                Status:  &status,
        }
-       err := m.callMeta("ModifyDuplication", req, func(resp interface{}) {})
+       err := m.callMeta("ModifyDuplication", req, func(_ interface{}) {})
        return err
 }
 
@@ -404,7 +404,7 @@ func (m *rpcBasedMeta) Balance(gpid *base.Gpid, opType 
BalanceType, from *util.P
        }
        req.ActionList = actions
 
-       err := m.callMeta("Balance", req, func(resp interface{}) {})
+       err := m.callMeta("Balance", req, func(_ interface{}) {})
        return err
 }
 
@@ -524,7 +524,7 @@ func (m *rpcBasedMeta) RestartPartitionSplit(tableName 
string, parentPidx int) e
 }
 
 func (m *rpcBasedMeta) CancelPartitionSplit(tableName string, 
oldPartitionCount int) error {
-       var partitionCount int32 = int32(oldPartitionCount)
+       partitionCount := int32(oldPartitionCount)
        req := &admin.ControlSplitRequest{
                AppName:           tableName,
                ControlType:       admin.SplitControlType_CANCEL,
@@ -615,8 +615,8 @@ func (m *rpcBasedMeta) ClearBulkLoad(tableName string) 
error {
 }
 
 func (m *rpcBasedMeta) StartManualCompaction(tableName string, targetLevel 
int, maxRunningCount int, bottommost bool) error {
-       var level int32 = int32(targetLevel)
-       var count int32 = int32(maxRunningCount)
+       level := int32(targetLevel)
+       count := int32(maxRunningCount)
        req := &admin.StartAppManualCompactRequest{
                AppName:         tableName,
                TargetLevel:     &level,
diff --git a/admin-cli/executor/server_config.go 
b/admin-cli/executor/server_config.go
index 70451e197..032cb4d63 100644
--- a/admin-cli/executor/server_config.go
+++ b/admin-cli/executor/server_config.go
@@ -90,7 +90,7 @@ func ConfigCommand(client *Client, nodeType session.NodeType, 
nodeAddr string, n
        return nil
 }
 
-func listConfig(addr string, cmd util.Arguments) (string, error) {
+func listConfig(addr string, _ util.Arguments) (string, error) {
        url := fmt.Sprintf("http://%s/configs";, addr)
        return util.CallHTTPGet(url)
 }
@@ -160,7 +160,7 @@ func updateConfig(addr string, cmd util.Arguments) (string, 
error) {
        return util.CallHTTPGet(url)
 }
 
-func printConfigUpdate(nodeType session.NodeType, sortedNodeList []string, 
results map[string]*util.Result) {
+func printConfigUpdate(_ session.NodeType, sortedNodeList []string, results 
map[string]*util.Result) {
        fmt.Printf("CMD: set \n")
        for _, node := range sortedNodeList {
                cmdRes := results[node]
diff --git a/admin-cli/executor/table_version.go 
b/admin-cli/executor/table_version.go
index 7ae742c2b..4a5810d70 100644
--- a/admin-cli/executor/table_version.go
+++ b/admin-cli/executor/table_version.go
@@ -71,13 +71,14 @@ func QueryReplicaDataVersion(client *Client, table string) 
(*TableDataVersion, e
                for _, version := range versions {
                        if finalVersion.DataVersion == "" {
                                finalVersion = version
-                       } else {
-                               if version.DataVersion == 
finalVersion.DataVersion {
-                                       continue
-                               } else {
-                                       return nil, fmt.Errorf("replica 
versions are not consistent")
-                               }
+                               continue
                        }
+
+                       if version.DataVersion == finalVersion.DataVersion {
+                               continue
+                       }
+
+                       return nil, fmt.Errorf("replica versions are not 
consistent")
                }
        }
        return &finalVersion, nil
diff --git a/admin-cli/tabular/template.go b/admin-cli/tabular/template.go
index 9e8ca4e79..f239dc4b5 100644
--- a/admin-cli/tabular/template.go
+++ b/admin-cli/tabular/template.go
@@ -225,7 +225,7 @@ func megabyteStatFormatter(v interface{}) string {
 type columnValueFormatter func(interface{}) string
 
 // The default column aggregate type, sum(value...)
-func defaultAggregator(rows int, totalRowColumns []string, index int, 
deltaValue float64) {
+func defaultAggregator(_ int, totalRowColumns []string, index int, deltaValue 
float64) {
        oldValue, _ := strconv.ParseFloat(totalRowColumns[index], 64)
        total := oldValue + deltaValue
        totalRowColumns[index] = strconv.FormatFloat(total, 'g', 5, 64)
diff --git a/admin-cli/util/common_utils.go b/admin-cli/util/common_utils.go
index bbeb14369..3a4cb042c 100644
--- a/admin-cli/util/common_utils.go
+++ b/admin-cli/util/common_utils.go
@@ -54,15 +54,21 @@ func SortStructsByField(structs []interface{}, key string) {
        sort.Slice(structs, func(i, j int) bool {
                v1 := reflect.ValueOf(structs[i]).FieldByName(key)
                v2 := reflect.ValueOf(structs[j]).FieldByName(key)
+
                if v1.Type().Name() == "string" {
                        return strings.Compare(v1.String(), v2.String()) < 0
-               } else if v1.Type().Name() == "int" || v1.Type().Name() == 
"int64" {
+               }
+
+               if v1.Type().Name() == "int" || v1.Type().Name() == "int64" {
                        return v1.Int() < v2.Int()
-               } else if v1.Type().Name() == "float64" {
+               }
+
+               if v1.Type().Name() == "float64" {
                        return v1.Float() < v2.Float()
-               } else {
-                       panic(fmt.Sprintf("Not support sort %s", 
v1.Type().Name()))
                }
+
+               panic(fmt.Sprintf("Not support sort %s", v1.Type().Name()))
+
        })
 }
 
diff --git a/collector/avail/detector.go b/collector/avail/detector.go
index d6ddfc27a..f285cb93f 100644
--- a/collector/avail/detector.go
+++ b/collector/avail/detector.go
@@ -44,9 +44,9 @@ func NewDetector(detectInterval time.Duration,
        tableName := 
viper.GetStringMapString("availablity_detect")["table_name"]
        // Create detect table.
        adminClient := admin.NewClient(admin.Config{MetaServers: metaServers})
-       error := adminClient.CreateTable(context.Background(), tableName, 
partitionCount)
-       if error != nil {
-               log.Errorf("Create detect table %s failed, error: %s", 
tableName, error)
+       err := adminClient.CreateTable(context.Background(), tableName, 
partitionCount)
+       if err != nil {
+               log.Errorf("Create detect table %s failed, error: %s", 
tableName, err)
        }
        pegasusClient := pegasus.NewClient(pegasus.Config{MetaServers: 
metaServers})
        return &pegasusDetector{
diff --git a/collector/metrics/metric_collector.go 
b/collector/metrics/metric_collector.go
index 6f7fcee78..1dad36ecf 100644
--- a/collector/metrics/metric_collector.go
+++ b/collector/metrics/metric_collector.go
@@ -357,7 +357,7 @@ func mergeIntoClusterLevelServerMetric(metrics 
[]gjson.Result, metricsOfCluster
                name := metric.Get("name").String()
                mtype := metric.Get("type").String()
                value := metric.Get("value").Float()
-               var isExisted bool = false
+               isExisted := false
                for _, m := range metricsOfCluster {
                        if m.name == name {
                                isExisted = true
diff --git a/collector/usage/usage_recorder.go 
b/collector/usage/usage_recorder.go
index d031e5f74..71bde4d8e 100644
--- a/collector/usage/usage_recorder.go
+++ b/collector/usage/usage_recorder.go
@@ -71,7 +71,7 @@ func (rec *tableUsageRecorder) Start(tom *tomb.Tomb) {
                break
        }
 
-       aggregate.AddHookAfterTableStatEmitted(func(stats 
[]aggregate.TableStats, allStat aggregate.ClusterStats) {
+       aggregate.AddHookAfterTableStatEmitted(func(stats 
[]aggregate.TableStats, _ aggregate.ClusterStats) {
                rootCtx := tom.Context(context.TODO())
                for _, s := range stats {
                        rec.writeTableUsage(rootCtx, &s)
diff --git a/go-client/.golangci.yml b/go-client/.golangci.yml
index 62e4ee83a..53c8fd044 100644
--- a/go-client/.golangci.yml
+++ b/go-client/.golangci.yml
@@ -24,3 +24,17 @@ linters:
   enable:
     - gofmt
     - goimports
+    - revive
+
+linters-settings:
+  revive:
+    rules:
+      # 
https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#var-naming
+      - name: var-naming
+        severity: warning
+        disabled: false
+        exclude: [""]
+        arguments:
+          - ["ID", "RPC"] # AllowList
+          - [] # DenyList
+          - - upperCaseConst: true # Extra parameter 
(upper-case-const|skip-package-name-checks)
diff --git a/go-client/admin/client_test.go b/go-client/admin/client_test.go
index ac1555077..a263c7c5a 100644
--- a/go-client/admin/client_test.go
+++ b/go-client/admin/client_test.go
@@ -55,7 +55,7 @@ func timeoutConfig() Config {
        }
 }
 
-func testAdmin_Timeout(t *testing.T, exec func(c Client) error) {
+func testAdminTimeout(t *testing.T, exec func(c Client) error) {
        c := NewClient(timeoutConfig())
        assert.Equal(t, context.DeadlineExceeded, exec(c))
 }
@@ -92,7 +92,7 @@ func TestAdmin_Table(t *testing.T) {
 }
 
 func TestAdmin_ListTablesTimeout(t *testing.T) {
-       testAdmin_Timeout(t, func(c Client) error {
+       testAdminTimeout(t, func(c Client) error {
                _, err := c.ListTables()
                return err
        })
@@ -183,7 +183,7 @@ func TestAdmin_ListNodes(t *testing.T) {
 }
 
 func TestAdmin_ListNodesTimeout(t *testing.T) {
-       testAdmin_Timeout(t, func(c Client) error {
+       testAdminTimeout(t, func(c Client) error {
                _, err := c.ListNodes()
                return err
        })
diff --git a/pegic/interactive/cmd/compression.go 
b/pegic/interactive/cmd/compression.go
index 4ab35e7b9..4ed5b5015 100644
--- a/pegic/interactive/cmd/compression.go
+++ b/pegic/interactive/cmd/compression.go
@@ -69,7 +69,7 @@ func init() {
        interactive.App.AddCommand(rootCmd)
 }
 
-func compressionCompleter(prefix string, args []string) []string {
+func compressionCompleter(prefix string, _ []string) []string {
        return filterStringWithPrefix([]string{
                "zstd",
                "no",
diff --git a/pegic/interactive/cmd/encoding.go 
b/pegic/interactive/cmd/encoding.go
index 98bad43ba..a7f401baf 100644
--- a/pegic/interactive/cmd/encoding.go
+++ b/pegic/interactive/cmd/encoding.go
@@ -96,7 +96,7 @@ func resetEncoding(c *grumble.Context, encPtr *util.Encoder) 
error {
        return nil
 }
 
-func encodingCompleter(prefix string, args []string) []string {
+func encodingCompleter(prefix string, _ []string) []string {
        return filterStringWithPrefix(supportedEncodings, prefix)
 }
 
diff --git a/pegic/shell/app.go b/pegic/shell/app.go
index db30e9dd0..47e308aa8 100644
--- a/pegic/shell/app.go
+++ b/pegic/shell/app.go
@@ -37,7 +37,7 @@ func init() {
        Root = &cobra.Command{
                Use:   "pegic [--meta|-m <meta-list>]",
                Short: "pegic: Pegasus Interactive Command-Line tool",
-               PreRun: func(c *cobra.Command, args []string) {
+               PreRun: func(c *cobra.Command, _ []string) {
                        metaAddrs := strings.Split(*metaList, ",")
                        err := cmd.Init(metaAddrs)
                        if err != nil {
@@ -45,7 +45,7 @@ func init() {
                                os.Exit(1)
                        }
                },
-               Run: func(cmd *cobra.Command, args []string) {
+               Run: func(_ *cobra.Command, _ []string) {
                        // the default entrance is interactive
                        interactive.Run()
                },


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to