Skip to content

Commit

Permalink
Merge pull request #458 from TarsCloud/feat/github/action
Browse files Browse the repository at this point in the history
feat: golangci-lint replace staticcheck
  • Loading branch information
lbbniu authored Apr 27, 2023
2 parents 0bfe718 + d641a5d commit 12c5859
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 23 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
name: reviewdog
on: [pull_request]
jobs:
staticcheck:
name: runner / staticcheck
golangci-lint:
runs-on: ubuntu-latest
name: runner / golangci-lint
steps:
- uses: actions/checkout@v2
- name: disable demo lint check
run: |
rm -rf tars/tools/Demo*
- uses: reviewdog/action-staticcheck@v1
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
# Report all results.
filter_mode: nofilter
# Exit with 1 when it find at least one finding.
# Exit with 1 when it finds at least one finding.
fail_on_error: true
# Set staticcheck flags
staticcheck_flags: -checks=inherit,-SA1019,-SA4001
#golangci_lint_flags
29 changes: 29 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
run:
timeout: 30m
skip-dirs:
- tars/protocol/res

linters:
disable-all: true
enable:
- unused
- ineffassign
- goimports
- gofmt
- misspell
- unparam
- unconvert
- govet
# - errcheck
- staticcheck

linters-settings:
staticcheck:
go: "1.17"
checks:
- "all"
# TODO(fix) Using a deprecated function, variable, constant or field
- "-SA1019"

unused:
go: "1.17"
2 changes: 2 additions & 0 deletions tars/protocol/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ func (b *Reader) unreadHead(curTag byte) {
}

// Next return the []byte of next n .
//
//go:nosplit
func (b *Reader) Next(n int) []byte {
if n <= 0 {
Expand All @@ -397,6 +398,7 @@ func (b *Reader) Next(n int) []byte {
}

// Skip the next n byte.
//
//go:nosplit
func (b *Reader) Skip(n int) {
if n <= 0 {
Expand Down
1 change: 1 addition & 0 deletions tars/protocol/tarsprotocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package protocol

import (
"encoding/binary"

"github.com/TarsCloud/TarsGo/tars/protocol/codec"
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
)
Expand Down
3 changes: 2 additions & 1 deletion tars/protocol/tarsprotocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package protocol
import (
"bytes"
"encoding/binary"
"testing"

"github.com/TarsCloud/TarsGo/tars/protocol/codec"
"github.com/TarsCloud/TarsGo/tars/protocol/res/basef"
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
"github.com/stretchr/testify/assert"
"testing"
)

func TestSetMaxPackageLength(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tars/protocol/tup/tup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (u *UniAttribute) PutBuffer(k string, buf []byte) {
func (u *UniAttribute) GetBuffer(k string, buf *[]byte) error {
var (
err error
ok = false
ok bool
)
if *buf, ok = u._data[k]; !ok {
err = fmt.Errorf("tup get error: donot find key: %s", k)
Expand Down
3 changes: 2 additions & 1 deletion tars/selector/roundrobin/round_robin_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package roundrobin

import (
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
"testing"

"github.com/TarsCloud/TarsGo/tars/util/endpoint"
)

func TestRoundRobin(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions tars/selector/selector.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package selector

import (
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
"math"
"sort"

"github.com/TarsCloud/TarsGo/tars/util/endpoint"
)

// HashType is the hash type
Expand Down Expand Up @@ -48,7 +49,8 @@ type Selector interface {
}

func BuildStaticWeightList(endpoints []endpoint.Endpoint) []int {
var maxRange, totalWeight, totalCapacity, minWeight, maxWeight = 0, 0, 0, math.MaxInt32, math.MinInt32
var maxRange, totalWeight, totalCapacity int
minWeight, maxWeight := math.MaxInt32, math.MinInt32
for _, node := range endpoints {
if endpoint.WeightType(node.WeightType) != endpoint.EStaticWeight {
return nil
Expand Down
6 changes: 3 additions & 3 deletions tars/util/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (e *elem) setValue(value string) *elem {
return e
}

func (e *elem) addChild(name string, child *elem) *elem {
func (e *elem) addChild(name string, child *elem) {
e.children[name] = child
return e
return
}

func (e *elem) addLine(line string) *elem {
Expand Down Expand Up @@ -158,7 +158,7 @@ func (e *elem) getMap(path string) (map[string]string, error) {
kvMap := make(map[string]string)
targetNode, err := e.getElem(pathVec)
if err != nil {
return kvMap, nil
return kvMap, err
}
for _, child := range targetNode.children {
if child.isLeaf() {
Expand Down
1 change: 1 addition & 0 deletions tars/util/grace/signal_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package grace
Expand Down
4 changes: 2 additions & 2 deletions tars/util/rtimer/timewheel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestTimeWheel(t *testing.T) {
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(1)
go func(i int) {
go func() {
start := time.Now().UnixNano()
<-After(sleepTime)
end := time.Now().UnixNano()
Expand All @@ -27,7 +27,7 @@ func TestTimeWheel(t *testing.T) {
deviation -= d
}
wg.Done()
}(i)
}()
time.Sleep(time.Millisecond * 100)
}
wg.Wait()
Expand Down
8 changes: 5 additions & 3 deletions tars/util/sync/once.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ type Once struct {

// Do calls the function f if and only if Do is being called for the
// first time for this instance of Once. In other words, given
// var once Once
//
// var once Once
//
// if once.Do(f) is called multiple times, only the first call will invoke f,
// even if f has a different value in each invocation. A new instance of
// Once is required for each function to execute.
//
// Do is intended for initialization that must be run exactly once. Since f
// is niladic, it may be necessary to use a function literal to capture the
// arguments to a function to be invoked by Do:
// config.once.Do(func() { config.init(filename) })
//
// config.once.Do(func() { config.init(filename) })
//
// Because no call to Do returns until the one call to f returns, if f causes
// Do to be called, it will deadlock.
//
// If f panics, Do considers it to have returned; future calls of Do return
// without calling f.
//
func (o *Once) Do(f func() error) error {
// Note: Here is an incorrect implementation of Do:
//
Expand Down

0 comments on commit 12c5859

Please sign in to comment.