diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index c7f8826..66e1464 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -16,28 +16,6 @@ jobs: - name: Check Spell uses: crate-ci/typos@master - staticcheck: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: stable - - - uses: reviewdog/action-staticcheck@v1 - 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 finds at least one finding. - fail_on_error: true - # Set staticcheck flags - # -ST1006 for fixing jit code receiver names like `self` - staticcheck_flags: -checks=inherit,-SA1029, -ST1006 - lint: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml deleted file mode 100644 index fb6cfcd..0000000 --- a/.github/workflows/release-check.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Release Check - -on: - pull_request: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Check Source Branch - run: python2 -c "exit(0 if '${{ github.head_ref }}'.startswith('release') or '${{ github.head_ref }}'.startswith('hotfix') else 1)" - - - name: Check Version - run: | - # get version code, runner not support grep -E here - SOURCE_VERSION=`grep 'Version\s*=\s*\"v[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\"' *.go | awk -F '\"' '{print $(NF-1)}'` - git checkout main - MASTER_VERSION=`grep 'Version\s*=\s*\"v[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\"' *.go | awk -F '\"' '{print $(NF-1)}'` - git checkout ${{Head.SHA}} - # check version update - python2 -c "exit(0 if list(map(int,'${SOURCE_VERSION#v}'.split('.')[:3])) > list(map(int,'${MASTER_VERSION#v}'.split('.')[:3])) else 1)" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b528582..68a192e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,8 +7,7 @@ jobs: strategy: matrix: go: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ] - os: [ X64 ] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.golangci.yaml b/.golangci.yaml index 71405b0..9584553 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,37 +1,10 @@ -# Options for analysis running. -run: - # include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin` - skip-dirs-use-default: true - skip-dirs: - - kitex_gen - skip-files: - - ".*\\.mock\\.go$" -# output configuration options -output: - # Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions - format: colored-line-number -# All available settings of specific linters. -# Refer to https://golangci-lint.run/usage/linters -linters-settings: - gofumpt: - # Choose whether to use the extra rules. - # Default: false - extra-rules: true - govet: - # Disable analyzers by name. - # Run `go tool vet help` to see all analyzers. - disable: - - stdmethods -linters: +linters: # https://golangci-lint.run/usage/linters/ + disable-all: true enable: - - gofumpt - - goimports - - gofmt - disable: - errcheck - - typecheck - - deadcode - - varcheck + - gosimple + - govet + - ineffassign - staticcheck -issues: - exclude-use-default: true + - unused + - unconvert diff --git a/container/strmap/strmap_test.go b/container/strmap/strmap_test.go index 7c56e01..712f287 100644 --- a/container/strmap/strmap_test.go +++ b/container/strmap/strmap_test.go @@ -28,7 +28,7 @@ import ( func randStrings(m, n int) []string { b := make([]byte, m*n) - rand.Read(b) + _, _ = rand.Read(b) ret := make([]string, 0, n) for i := 0; i < n; i++ { s := b[m*i:] @@ -173,7 +173,7 @@ func BenchmarkLoadFromMap(b *testing.B) { p := New[uint]() b.ResetTimer() for i := 0; i < b.N; i++ { - p.LoadFromMap(m) + _ = p.LoadFromMap(m) } } @@ -188,7 +188,7 @@ func BenchmarkLoadFromSlice(b *testing.B) { p := New[int]() b.ResetTimer() for i := 0; i < b.N; i++ { - p.LoadFromSlice(kk, vv) + _ = p.LoadFromSlice(kk, vv) } } diff --git a/internal/strstore/strstore_test.go b/internal/strstore/strstore_test.go index a76a1c2..1f5e034 100644 --- a/internal/strstore/strstore_test.go +++ b/internal/strstore/strstore_test.go @@ -82,7 +82,7 @@ func BenchmarkStrStoreLoad(b *testing.B) { strStore := New() b.ResetTimer() for i := 0; i < b.N; i++ { - strStore.Load(ss) + _, _ = strStore.Load(ss) } } diff --git a/protocol/thrift/binary_test.go b/protocol/thrift/binary_test.go index 5eb7740..52016e8 100644 --- a/protocol/thrift/binary_test.go +++ b/protocol/thrift/binary_test.go @@ -30,12 +30,12 @@ func TestBinary(t *testing.T) { b := Binary.AppendBool([]byte(nil), true) b = Binary.AppendBool(b, false) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteBool(b1, true) l += Binary.WriteBool(b1[l:], false) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadBool(b) @@ -53,11 +53,11 @@ func TestBinary(t *testing.T) { sz := Binary.ByteLength() b := Binary.AppendByte([]byte(nil), 1) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteByte(b1, 1) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadByte(b) @@ -73,11 +73,11 @@ func TestBinary(t *testing.T) { sz := Binary.I16Length() b := Binary.AppendI16([]byte(nil), testv) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteI16(b1, testv) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadI16(b) @@ -93,11 +93,11 @@ func TestBinary(t *testing.T) { sz := Binary.I32Length() b := Binary.AppendI32([]byte(nil), testv) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteI32(b1, testv) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadI32(b) @@ -113,11 +113,11 @@ func TestBinary(t *testing.T) { sz := Binary.I64Length() b := Binary.AppendI64([]byte(nil), testv) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteI64(b1, testv) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadI64(b) @@ -133,11 +133,11 @@ func TestBinary(t *testing.T) { sz := Binary.DoubleLength() b := Binary.AppendDouble([]byte(nil), testv) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteDouble(b1, testv) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadDouble(b) @@ -153,11 +153,11 @@ func TestBinary(t *testing.T) { sz := Binary.BinaryLength(testv) b := Binary.AppendBinary([]byte(nil), testv) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteBinaryNocopy(b1, nil, testv) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadBinary(b) @@ -173,11 +173,11 @@ func TestBinary(t *testing.T) { sz := Binary.StringLength(testv) b := Binary.AppendString([]byte(nil), testv) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteStringNocopy(b1, nil, testv) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) v, l, _ := Binary.ReadString(b) @@ -193,11 +193,11 @@ func TestBinary(t *testing.T) { sz := Binary.MessageBeginLength(testname) b := Binary.AppendMessageBegin([]byte(nil), testname, testtyp, testseq) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteMessageBegin(b1, testname, testtyp, testseq) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) name, typ, seq, l, _ := Binary.ReadMessageBegin(b) @@ -216,12 +216,12 @@ func TestBinary(t *testing.T) { b := Binary.AppendFieldBegin([]byte(nil), testtyp, testfid) b = Binary.AppendFieldStop(b) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteFieldBegin(b1, testtyp, testfid) l += Binary.WriteFieldStop(b1[l:]) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) typ, fid, l, _ := Binary.ReadFieldBegin(b) @@ -243,11 +243,11 @@ func TestBinary(t *testing.T) { sz := Binary.MapBeginLength() b := Binary.AppendMapBegin([]byte(nil), testkt, testvt, testsize) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteMapBegin(b1, testkt, testvt, testsize) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) kt, vt, size, l, _ := Binary.ReadMapBegin(b) @@ -265,11 +265,11 @@ func TestBinary(t *testing.T) { sz := Binary.ListBeginLength() b := Binary.AppendListBegin([]byte(nil), testvt, testsize) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteListBegin(b1, testvt, testsize) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) vt, size, l, _ := Binary.ReadListBegin(b) @@ -286,11 +286,11 @@ func TestBinary(t *testing.T) { sz := Binary.SetBeginLength() b := Binary.AppendSetBegin([]byte(nil), testvt, testsize) - require.Equal(t, int(sz), len(b)) + require.Equal(t, sz, len(b)) b1 := make([]byte, sz) l := Binary.WriteSetBegin(b1, testvt, testsize) - require.Equal(t, int(sz), l) + require.Equal(t, sz, l) require.Equal(t, b, b1) vt, size, l, _ := Binary.ReadSetBegin(b) diff --git a/protocol/thrift/bufferreader.go b/protocol/thrift/bufferreader.go index f4d0105..4e05853 100644 --- a/protocol/thrift/bufferreader.go +++ b/protocol/thrift/bufferreader.go @@ -274,7 +274,7 @@ func (r *BufferReader) skipType(t TType, maxdepth int) error { } ksz, vsz := int(typeToSize[kt]), int(typeToSize[vt]) if ksz > 0 && vsz > 0 { - return r.skipn(int(sz) * (ksz + vsz)) + return r.skipn(sz * (ksz + vsz)) } for j := 0; j < sz; j++ { if ksz > 0 { diff --git a/protocol/thrift/bufferwriter_test.go b/protocol/thrift/bufferwriter_test.go index c9e176f..1442f29 100644 --- a/protocol/thrift/bufferwriter_test.go +++ b/protocol/thrift/bufferwriter_test.go @@ -32,48 +32,48 @@ func TestBinaryWriter(t *testing.T) { x := BinaryProtocol{} b := x.AppendMessageBegin(nil, "hello", 1, 2) - w.WriteMessageBegin("hello", 1, 2) + _ = w.WriteMessageBegin("hello", 1, 2) b = x.AppendFieldBegin(b, 3, 4) - w.WriteFieldBegin(3, 4) + _ = w.WriteFieldBegin(3, 4) b = x.AppendFieldStop(b) - w.WriteFieldStop() + _ = w.WriteFieldStop() b = x.AppendMapBegin(b, 5, 6, 7) - w.WriteMapBegin(5, 6, 7) + _ = w.WriteMapBegin(5, 6, 7) b = x.AppendListBegin(b, 8, 9) - w.WriteListBegin(8, 9) + _ = w.WriteListBegin(8, 9) b = x.AppendSetBegin(b, 10, 11) - w.WriteSetBegin(10, 11) + _ = w.WriteSetBegin(10, 11) b = x.AppendBinary(b, []byte("12")) - w.WriteBinary([]byte("12")) + _ = w.WriteBinary([]byte("12")) b = x.AppendString(b, "13") - w.WriteString("13") + _ = w.WriteString("13") b = x.AppendBool(b, true) b = x.AppendBool(b, false) - w.WriteBool(true) - w.WriteBool(false) + _ = w.WriteBool(true) + _ = w.WriteBool(false) b = x.AppendByte(b, 14) - w.WriteByte(14) + _ = w.WriteByte(14) b = x.AppendI16(b, 15) - w.WriteI16(15) + _ = w.WriteI16(15) b = x.AppendI32(b, 16) - w.WriteI32(16) + _ = w.WriteI32(16) b = x.AppendI64(b, 17) - w.WriteI64(17) + _ = w.WriteI64(17) b = x.AppendDouble(b, 18.5) - w.WriteDouble(18.5) + _ = w.WriteDouble(18.5) w.w.Flush() w.Recycle() diff --git a/protocol/thrift/skipdecoder_test.go b/protocol/thrift/skipdecoder_test.go index 6e3eafa..60a5e7a 100644 --- a/protocol/thrift/skipdecoder_test.go +++ b/protocol/thrift/skipdecoder_test.go @@ -229,7 +229,7 @@ func BenchmarkSkipDecoder(b *testing.B) { b.Fatal("bytes not equal") } sr.Release() - bufReader.Release(nil) + _ = bufReader.Release(nil) } }) } diff --git a/protocol/thrift/utils.go b/protocol/thrift/utils.go index 3b4a34f..582fa6f 100644 --- a/protocol/thrift/utils.go +++ b/protocol/thrift/utils.go @@ -27,11 +27,3 @@ func p2i32(p unsafe.Pointer) int32 { uint32(*(*byte)(unsafe.Add(p, 1)))<<16 | uint32(*(*byte)(p))<<24) } - -type nextIface interface { - Next(n int) ([]byte, error) -} - -type discardIface interface { - Discard(n int) (int, error) -} diff --git a/protocol/ttheader/encode_test.go b/protocol/ttheader/encode_test.go index 5507eeb..2a20bdd 100644 --- a/protocol/ttheader/encode_test.go +++ b/protocol/ttheader/encode_test.go @@ -78,7 +78,7 @@ func TestEncode(t *testing.T) { t.Errorf("decode failed, %s", err.Error()) return } - br.Release(nil) + _ = br.Release(nil) l.Close() conn.Close() }()