Skip to content

Commit 12c5859

Browse files
authored
Merge pull request #458 from TarsCloud/feat/github/action
feat: golangci-lint replace staticcheck
2 parents 0bfe718 + d641a5d commit 12c5859

File tree

12 files changed

+60
-23
lines changed

12 files changed

+60
-23
lines changed

.github/workflows/reviewdog.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
name: reviewdog
22
on: [pull_request]
33
jobs:
4-
staticcheck:
5-
name: runner / staticcheck
4+
golangci-lint:
65
runs-on: ubuntu-latest
6+
name: runner / golangci-lint
77
steps:
8-
- uses: actions/checkout@v2
9-
- name: disable demo lint check
10-
run: |
11-
rm -rf tars/tools/Demo*
12-
- uses: reviewdog/action-staticcheck@v1
8+
- name: Check out code into the Go module directory
9+
uses: actions/checkout@v3
10+
- name: golangci-lint
11+
uses: reviewdog/action-golangci-lint@v2
1312
with:
1413
github_token: ${{ secrets.github_token }}
1514
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
1615
reporter: github-pr-review
1716
# Report all results.
1817
filter_mode: nofilter
19-
# Exit with 1 when it find at least one finding.
18+
# Exit with 1 when it finds at least one finding.
2019
fail_on_error: true
21-
# Set staticcheck flags
22-
staticcheck_flags: -checks=inherit,-SA1019,-SA4001
20+
#golangci_lint_flags

.golangci.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
run:
2+
timeout: 30m
3+
skip-dirs:
4+
- tars/protocol/res
5+
6+
linters:
7+
disable-all: true
8+
enable:
9+
- unused
10+
- ineffassign
11+
- goimports
12+
- gofmt
13+
- misspell
14+
- unparam
15+
- unconvert
16+
- govet
17+
# - errcheck
18+
- staticcheck
19+
20+
linters-settings:
21+
staticcheck:
22+
go: "1.17"
23+
checks:
24+
- "all"
25+
# TODO(fix) Using a deprecated function, variable, constant or field
26+
- "-SA1019"
27+
28+
unused:
29+
go: "1.17"

tars/protocol/codec/codec.go

+2
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ func (b *Reader) unreadHead(curTag byte) {
385385
}
386386

387387
// Next return the []byte of next n .
388+
//
388389
//go:nosplit
389390
func (b *Reader) Next(n int) []byte {
390391
if n <= 0 {
@@ -397,6 +398,7 @@ func (b *Reader) Next(n int) []byte {
397398
}
398399

399400
// Skip the next n byte.
401+
//
400402
//go:nosplit
401403
func (b *Reader) Skip(n int) {
402404
if n <= 0 {

tars/protocol/tarsprotocol.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package protocol
22

33
import (
44
"encoding/binary"
5+
56
"github.com/TarsCloud/TarsGo/tars/protocol/codec"
67
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
78
)

tars/protocol/tarsprotocol_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package protocol
33
import (
44
"bytes"
55
"encoding/binary"
6+
"testing"
7+
68
"github.com/TarsCloud/TarsGo/tars/protocol/codec"
79
"github.com/TarsCloud/TarsGo/tars/protocol/res/basef"
810
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
911
"github.com/stretchr/testify/assert"
10-
"testing"
1112
)
1213

1314
func TestSetMaxPackageLength(t *testing.T) {

tars/protocol/tup/tup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (u *UniAttribute) PutBuffer(k string, buf []byte) {
3030
func (u *UniAttribute) GetBuffer(k string, buf *[]byte) error {
3131
var (
3232
err error
33-
ok = false
33+
ok bool
3434
)
3535
if *buf, ok = u._data[k]; !ok {
3636
err = fmt.Errorf("tup get error: donot find key: %s", k)

tars/selector/roundrobin/round_robin_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package roundrobin
22

33
import (
4-
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
54
"testing"
5+
6+
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
67
)
78

89
func TestRoundRobin(t *testing.T) {

tars/selector/selector.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package selector
22

33
import (
4-
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
54
"math"
65
"sort"
6+
7+
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
78
)
89

910
// HashType is the hash type
@@ -48,7 +49,8 @@ type Selector interface {
4849
}
4950

5051
func BuildStaticWeightList(endpoints []endpoint.Endpoint) []int {
51-
var maxRange, totalWeight, totalCapacity, minWeight, maxWeight = 0, 0, 0, math.MaxInt32, math.MinInt32
52+
var maxRange, totalWeight, totalCapacity int
53+
minWeight, maxWeight := math.MaxInt32, math.MinInt32
5254
for _, node := range endpoints {
5355
if endpoint.WeightType(node.WeightType) != endpoint.EStaticWeight {
5456
return nil

tars/util/conf/conf.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func (e *elem) setValue(value string) *elem {
4343
return e
4444
}
4545

46-
func (e *elem) addChild(name string, child *elem) *elem {
46+
func (e *elem) addChild(name string, child *elem) {
4747
e.children[name] = child
48-
return e
48+
return
4949
}
5050

5151
func (e *elem) addLine(line string) *elem {
@@ -158,7 +158,7 @@ func (e *elem) getMap(path string) (map[string]string, error) {
158158
kvMap := make(map[string]string)
159159
targetNode, err := e.getElem(pathVec)
160160
if err != nil {
161-
return kvMap, nil
161+
return kvMap, err
162162
}
163163
for _, child := range targetNode.children {
164164
if child.isLeaf() {

tars/util/grace/signal_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package grace

tars/util/rtimer/timewheel_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestTimeWheel(t *testing.T) {
1616
wg := sync.WaitGroup{}
1717
for i := 0; i < 100; i++ {
1818
wg.Add(1)
19-
go func(i int) {
19+
go func() {
2020
start := time.Now().UnixNano()
2121
<-After(sleepTime)
2222
end := time.Now().UnixNano()
@@ -27,7 +27,7 @@ func TestTimeWheel(t *testing.T) {
2727
deviation -= d
2828
}
2929
wg.Done()
30-
}(i)
30+
}()
3131
time.Sleep(time.Millisecond * 100)
3232
}
3333
wg.Wait()

tars/util/sync/once.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ type Once struct {
2424

2525
// Do calls the function f if and only if Do is being called for the
2626
// first time for this instance of Once. In other words, given
27-
// var once Once
27+
//
28+
// var once Once
29+
//
2830
// if once.Do(f) is called multiple times, only the first call will invoke f,
2931
// even if f has a different value in each invocation. A new instance of
3032
// Once is required for each function to execute.
3133
//
3234
// Do is intended for initialization that must be run exactly once. Since f
3335
// is niladic, it may be necessary to use a function literal to capture the
3436
// arguments to a function to be invoked by Do:
35-
// config.once.Do(func() { config.init(filename) })
37+
//
38+
// config.once.Do(func() { config.init(filename) })
3639
//
3740
// Because no call to Do returns until the one call to f returns, if f causes
3841
// Do to be called, it will deadlock.
3942
//
4043
// If f panics, Do considers it to have returned; future calls of Do return
4144
// without calling f.
42-
//
4345
func (o *Once) Do(f func() error) error {
4446
// Note: Here is an incorrect implementation of Do:
4547
//

0 commit comments

Comments
 (0)