Skip to content

Commit ae6ace2

Browse files
authored
ci: introduce revive as the linter replacement for golint (apache#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.
1 parent 5b229e5 commit ae6ace2

File tree

18 files changed

+85
-50
lines changed

18 files changed

+85
-50
lines changed

.github/workflows/lint_and_test_admin-cli.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- '*dev'
3131
paths:
3232
- .github/workflows/lint_and_test_admin-cli.yml
33+
- .golangci.yml
3334
- admin-cli/**
3435

3536
# for manually triggering workflow

.github/workflows/lint_and_test_collector.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- '*dev'
3131
paths:
3232
- .github/workflows/lint_and_test_collector.yml
33+
- .golangci.yml
3334
- collector/**
3435
- go-client/**
3536

.github/workflows/lint_and_test_pegic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- '*dev'
3131
paths:
3232
- .github/workflows/lint_and_test_pegic.yml
33+
- .golangci.yml
3334
- pegic/**
3435

3536
# for manually triggering workflow

.golangci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ linters:
2727
enable:
2828
- gofmt
2929
- goimports
30-
- golint
30+
- revive
3131
- bodyclose
3232
- exhaustive
3333
- exportloopref
3434

3535
linters-settings:
36+
revive:
37+
rules:
38+
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#var-naming
39+
- name: var-naming
40+
severity: warning
41+
disabled: false
42+
exclude: [""]
43+
arguments:
44+
- ["ID", "RPC"] # AllowList
45+
- [] # DenyList
46+
- - upperCaseConst: true # Extra parameter (upper-case-const|skip-package-name-checks)
3647
exhaustive:
3748
# indicates that switch statements are to be considered exhaustive if a
3849
# 'default' case is present, even if all enum members aren't listed in the

admin-cli/client/fake_meta_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (m *fakeMeta) Balance(pid *base.Gpid, opType BalanceType, from *util.Pegasu
167167
return nil
168168
}
169169

170-
func (m *fakeMeta) Propose(pid *base.Gpid, opType admin.ConfigType, target *util.PegasusNode, node *util.PegasusNode) error {
170+
func (m *fakeMeta) Propose(pid *base.Gpid, opType admin.ConfigType, _ *util.PegasusNode, node *util.PegasusNode) error {
171171
fakeNode := findNodeInFakeCluster(node)
172172

173173
switch opType {
@@ -193,67 +193,67 @@ func findNodeInFakeCluster(pn *util.PegasusNode) *fakeNode {
193193
return ret
194194
}
195195

196-
func (m *fakeMeta) StartBackupApp(tableID int, providerType string, backupPath string) (*admin.StartBackupAppResponse, error) {
196+
func (m *fakeMeta) StartBackupApp(_ int, _ string, _ string) (*admin.StartBackupAppResponse, error) {
197197
panic("unimplemented")
198198
}
199199

200-
func (m *fakeMeta) QueryBackupStatus(tableID int, backupID int64) (*admin.QueryBackupStatusResponse, error) {
200+
func (m *fakeMeta) QueryBackupStatus(_ int, _ int64) (*admin.QueryBackupStatusResponse, error) {
201201
panic("unimplemented")
202202
}
203203

204-
func (m *fakeMeta) RestoreApp(oldClusterName string, oldTableName string, oldTableID int, backupID int64, providerType string,
205-
newTableName string, restorePath string, skipBadPartition bool, policyName string) (*admin.CreateAppResponse, error) {
204+
func (m *fakeMeta) RestoreApp(_ string, _ string, _ int, _ int64, _ string,
205+
_ string, _ string, _ bool, _ string) (*admin.CreateAppResponse, error) {
206206
panic("unimplemented")
207207
}
208208

209-
func (m *fakeMeta) StartPartitionSplit(tableName string, newPartitionCount int) error {
209+
func (m *fakeMeta) StartPartitionSplit(_ string, _ int) error {
210210
panic("unimplemented")
211211
}
212212

213-
func (m *fakeMeta) QuerySplitStatus(tableName string) (*admin.QuerySplitResponse, error) {
213+
func (m *fakeMeta) QuerySplitStatus(_ string) (*admin.QuerySplitResponse, error) {
214214
panic("unimplemented")
215215
}
216216

217-
func (m *fakeMeta) PausePartitionSplit(tableName string, parentPidx int) error {
217+
func (m *fakeMeta) PausePartitionSplit(_ string, _ int) error {
218218
panic("unimplemented")
219219
}
220220

221-
func (m *fakeMeta) RestartPartitionSplit(tableName string, parentPidx int) error {
221+
func (m *fakeMeta) RestartPartitionSplit(_ string, _ int) error {
222222
panic("unimplemented")
223223
}
224224

225-
func (m *fakeMeta) CancelPartitionSplit(tableName string, oldPartitionCount int) error {
225+
func (m *fakeMeta) CancelPartitionSplit(_ string, _ int) error {
226226
panic("unimplemented")
227227
}
228228

229-
func (m *fakeMeta) StartBulkLoad(tableName string, clusterName string, providerType string, rootPath string) error {
229+
func (m *fakeMeta) StartBulkLoad(_ string, _ string, _ string, _ string) error {
230230
panic("unimplemented")
231231
}
232232

233-
func (m *fakeMeta) QueryBulkLoad(tableName string) (*admin.QueryBulkLoadResponse, error) {
233+
func (m *fakeMeta) QueryBulkLoad(_ string) (*admin.QueryBulkLoadResponse, error) {
234234
panic("unimplemented")
235235
}
236236

237-
func (m *fakeMeta) PauseBulkLoad(tableName string) error {
237+
func (m *fakeMeta) PauseBulkLoad(_ string) error {
238238
panic("unimplemented")
239239
}
240240

241-
func (m *fakeMeta) RestartBulkLoad(tableName string) error {
241+
func (m *fakeMeta) RestartBulkLoad(_ string) error {
242242
panic("unimplemented")
243243
}
244244

245-
func (m *fakeMeta) CancelBulkLoad(tableName string, forced bool) error {
245+
func (m *fakeMeta) CancelBulkLoad(_ string, _ bool) error {
246246
panic("unimplemented")
247247
}
248248

249-
func (m *fakeMeta) ClearBulkLoad(tableName string) error {
249+
func (m *fakeMeta) ClearBulkLoad(_ string) error {
250250
panic("unimplemented")
251251
}
252252

253-
func (m *fakeMeta) StartManualCompaction(tableName string, targetLevel int, maxRunningCount int, bottommost bool) error {
253+
func (m *fakeMeta) StartManualCompaction(_ string, _ int, _ int, _ bool) error {
254254
panic("unimplemented")
255255
}
256256

257-
func (m *fakeMeta) QueryManualCompaction(tableName string) (*admin.QueryAppManualCompactResponse, error) {
257+
func (m *fakeMeta) QueryManualCompaction(_ string) (*admin.QueryAppManualCompactResponse, error) {
258258
panic("unimplemented")
259259
}

admin-cli/client/meta.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (m *rpcBasedMeta) DropApp(tableName string, reserveSeconds int64) error {
302302
ReserveSeconds: &reserveSeconds,
303303
},
304304
}
305-
err := m.callMeta("DropApp", req, func(resp interface{}) {})
305+
err := m.callMeta("DropApp", req, func(_ interface{}) {})
306306
return err
307307
}
308308

@@ -312,7 +312,7 @@ func (m *rpcBasedMeta) ModifyDuplication(tableName string, dupid int, status adm
312312
Dupid: int32(dupid),
313313
Status: &status,
314314
}
315-
err := m.callMeta("ModifyDuplication", req, func(resp interface{}) {})
315+
err := m.callMeta("ModifyDuplication", req, func(_ interface{}) {})
316316
return err
317317
}
318318

@@ -404,7 +404,7 @@ func (m *rpcBasedMeta) Balance(gpid *base.Gpid, opType BalanceType, from *util.P
404404
}
405405
req.ActionList = actions
406406

407-
err := m.callMeta("Balance", req, func(resp interface{}) {})
407+
err := m.callMeta("Balance", req, func(_ interface{}) {})
408408
return err
409409
}
410410

@@ -524,7 +524,7 @@ func (m *rpcBasedMeta) RestartPartitionSplit(tableName string, parentPidx int) e
524524
}
525525

526526
func (m *rpcBasedMeta) CancelPartitionSplit(tableName string, oldPartitionCount int) error {
527-
var partitionCount int32 = int32(oldPartitionCount)
527+
partitionCount := int32(oldPartitionCount)
528528
req := &admin.ControlSplitRequest{
529529
AppName: tableName,
530530
ControlType: admin.SplitControlType_CANCEL,
@@ -615,8 +615,8 @@ func (m *rpcBasedMeta) ClearBulkLoad(tableName string) error {
615615
}
616616

617617
func (m *rpcBasedMeta) StartManualCompaction(tableName string, targetLevel int, maxRunningCount int, bottommost bool) error {
618-
var level int32 = int32(targetLevel)
619-
var count int32 = int32(maxRunningCount)
618+
level := int32(targetLevel)
619+
count := int32(maxRunningCount)
620620
req := &admin.StartAppManualCompactRequest{
621621
AppName: tableName,
622622
TargetLevel: &level,

admin-cli/executor/server_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func ConfigCommand(client *Client, nodeType session.NodeType, nodeAddr string, n
9090
return nil
9191
}
9292

93-
func listConfig(addr string, cmd util.Arguments) (string, error) {
93+
func listConfig(addr string, _ util.Arguments) (string, error) {
9494
url := fmt.Sprintf("http://%s/configs", addr)
9595
return util.CallHTTPGet(url)
9696
}
@@ -160,7 +160,7 @@ func updateConfig(addr string, cmd util.Arguments) (string, error) {
160160
return util.CallHTTPGet(url)
161161
}
162162

163-
func printConfigUpdate(nodeType session.NodeType, sortedNodeList []string, results map[string]*util.Result) {
163+
func printConfigUpdate(_ session.NodeType, sortedNodeList []string, results map[string]*util.Result) {
164164
fmt.Printf("CMD: set \n")
165165
for _, node := range sortedNodeList {
166166
cmdRes := results[node]

admin-cli/executor/table_version.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ func QueryReplicaDataVersion(client *Client, table string) (*TableDataVersion, e
7171
for _, version := range versions {
7272
if finalVersion.DataVersion == "" {
7373
finalVersion = version
74-
} else {
75-
if version.DataVersion == finalVersion.DataVersion {
76-
continue
77-
} else {
78-
return nil, fmt.Errorf("replica versions are not consistent")
79-
}
74+
continue
8075
}
76+
77+
if version.DataVersion == finalVersion.DataVersion {
78+
continue
79+
}
80+
81+
return nil, fmt.Errorf("replica versions are not consistent")
8182
}
8283
}
8384
return &finalVersion, nil

admin-cli/tabular/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func megabyteStatFormatter(v interface{}) string {
225225
type columnValueFormatter func(interface{}) string
226226

227227
// The default column aggregate type, sum(value...)
228-
func defaultAggregator(rows int, totalRowColumns []string, index int, deltaValue float64) {
228+
func defaultAggregator(_ int, totalRowColumns []string, index int, deltaValue float64) {
229229
oldValue, _ := strconv.ParseFloat(totalRowColumns[index], 64)
230230
total := oldValue + deltaValue
231231
totalRowColumns[index] = strconv.FormatFloat(total, 'g', 5, 64)

admin-cli/util/common_utils.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,21 @@ func SortStructsByField(structs []interface{}, key string) {
5454
sort.Slice(structs, func(i, j int) bool {
5555
v1 := reflect.ValueOf(structs[i]).FieldByName(key)
5656
v2 := reflect.ValueOf(structs[j]).FieldByName(key)
57+
5758
if v1.Type().Name() == "string" {
5859
return strings.Compare(v1.String(), v2.String()) < 0
59-
} else if v1.Type().Name() == "int" || v1.Type().Name() == "int64" {
60+
}
61+
62+
if v1.Type().Name() == "int" || v1.Type().Name() == "int64" {
6063
return v1.Int() < v2.Int()
61-
} else if v1.Type().Name() == "float64" {
64+
}
65+
66+
if v1.Type().Name() == "float64" {
6267
return v1.Float() < v2.Float()
63-
} else {
64-
panic(fmt.Sprintf("Not support sort %s", v1.Type().Name()))
6568
}
69+
70+
panic(fmt.Sprintf("Not support sort %s", v1.Type().Name()))
71+
6672
})
6773
}
6874

0 commit comments

Comments
 (0)