Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deepsource: RVV-B0001 Confusing naming of struct fields or methods #1875

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/info/info.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//
//
// Copyright (C) 2019-2022 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -262,11 +263,11 @@ func (d Detail) String() string {
// Get returns parased Detail object.
func (i *info) Get() Detail {
i.prepare()
return i.get()
return i.getDetail()
}

// skipcq: VET-V0008
func (i info) get() Detail {
func (i info) getDetail() Detail {
kevindiu marked this conversation as resolved.
Show resolved Hide resolved
i.detail.StackTrace = make([]StackTrace, 0, 10)
for j := 2; ; j++ {
pc, file, line, ok := i.rtCaller(j)
Expand Down
4 changes: 2 additions & 2 deletions internal/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ func TestStackTrace_String(t *testing.T) {
}
}

func Test_info_get(t *testing.T) {
func Test_info_getDetail(t *testing.T) {
type fields struct {
baseURL string
detail Detail
Expand Down Expand Up @@ -1649,7 +1649,7 @@ func Test_info_get(t *testing.T) {
rtFuncForPC: test.fields.rtFuncForPC,
}

got := i.get()
got := i.getDetail()
if err := checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/net/grpc/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ func (p *pool) Do(f func(conn *ClientConn) error) error {
}

func (p *pool) Get() (*ClientConn, bool) {
return p.get(p.Len())
return p.doGet(p.Len())
}

func (p *pool) get(retry uint64) (*ClientConn, bool) {
func (p *pool) doGet(retry uint64) (*ClientConn, bool) {
if retry <= 0 || retry > math.MaxUint64-p.Len() || p.Len() <= 0 {
log.Warnf("failed to find grpc pool connection for %s", p.addr)
if p.isIP {
Expand All @@ -378,7 +378,7 @@ func (p *pool) get(retry uint64) (*ClientConn, bool) {
}
}
retry--
return p.get(retry)
return p.doGet(retry)
}

func (p *pool) Len() uint64 {
Expand Down
4 changes: 2 additions & 2 deletions internal/net/grpc/pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ func Test_pool_Get(t *testing.T) {
}
}

func Test_pool_get(t *testing.T) {
func Test_pool_doGet(t *testing.T) {
t.Parallel()
type args struct {
retry uint64
Expand Down Expand Up @@ -1426,7 +1426,7 @@ func Test_pool_get(t *testing.T) {
reconnectHash: test.fields.reconnectHash,
}

got, got1 := p.get(test.args.retry)
got, got1 := p.doGet(test.args.retry)
if err := checkFunc(test.want, got, got1); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down
16 changes: 8 additions & 8 deletions internal/test/data/vector/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func Uint8VectorGenerator(d Distribution) (Uint8VectorGeneratorFunc, error) {
}
}

// genFloat32Vec return n float32 vectors with dim dimension.
func genFloat32Vec(n, dim int, gen func() float32) (ret [][]float32) {
// doGenFloat32Vec return n float32 vectors with dim dimension.
func doGenFloat32Vec(n, dim int, gen func() float32) (ret [][]float32) {
ret = make([][]float32, 0, n)

for i := 0; i < n; i++ {
Expand All @@ -79,18 +79,18 @@ func genFloat32Vec(n, dim int, gen func() float32) (ret [][]float32) {

// UniformDistributedFloat32VectorGenerator returns n float32 vectors with dim dimension and their values under Uniform distribution
func UniformDistributedFloat32VectorGenerator(n, dim int) [][]float32 {
return genFloat32Vec(n, dim, rand.Float32)
return doGenFloat32Vec(n, dim, rand.Float32)
}

// GaussianDistributedFloat32VectorGenerator returns n float32 vectors with dim dimension and their values under Gaussian distribution
func GaussianDistributedFloat32VectorGenerator(n, dim int) [][]float32 {
return genFloat32Vec(n, dim, func() float32 {
return doGenFloat32Vec(n, dim, func() float32 {
return float32(rand.NormFloat64())
})
}

// genUint8Vec return n uint8 vectors with dim dimension
func genUint8Vec(n, dim int, gen func() uint8) (ret [][]uint8) {
// doGenUint8Vec return n uint8 vectors with dim dimension
func doGenUint8Vec(n, dim int, gen func() uint8) (ret [][]uint8) {
ret = make([][]uint8, 0, n)

for i := 0; i < n; i++ {
Expand All @@ -105,15 +105,15 @@ func genUint8Vec(n, dim int, gen func() uint8) (ret [][]uint8) {

// UniformDistributedUint8VectorGenerator returns n uint8 vectors with dim dimension and their values under Uniform distribution
func UniformDistributedUint8VectorGenerator(n, dim int) [][]uint8 {
return genUint8Vec(n, dim, func() uint8 {
return doGenUint8Vec(n, dim, func() uint8 {
return uint8(irand.LimitedUint32(math.MaxUint8))
})
}

// GaussianDistributedUint8VectorGenerator returns n uint8 vectors with dim dimension and their values under Gaussian distribution
func GaussianDistributedUint8VectorGenerator(n, dim int) [][]uint8 {
// NOTE: The boundary test is the main purpose for refactoring. Now, passing this function is dependent on the seed of the random generator. We should fix the randomness of the passing test.
return genUint8Vec(n, dim, func() uint8 {
return doGenUint8Vec(n, dim, func() uint8 {
val := rand.NormFloat64()*gaussianSigma + gaussianMean
if val < 0 {
return 0
Expand Down
8 changes: 4 additions & 4 deletions internal/test/data/vector/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestUint8VectorGenerator(t *testing.T) {
}
}

func Test_genFloat32Vec(t *testing.T) {
func Test_doGenFloat32Vec(t *testing.T) {
type args struct {
n int
dim int
Expand Down Expand Up @@ -279,7 +279,7 @@ func Test_genFloat32Vec(t *testing.T) {
checkFunc = defaultCheckFunc
}

gotRet := genFloat32Vec(test.args.n, test.args.dim, test.args.gen)
gotRet := doGenFloat32Vec(test.args.n, test.args.dim, test.args.gen)
if err := checkFunc(test.want, gotRet); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestGaussianDistributedFloat32VectorGenerator(t *testing.T) {
}
}

func Test_genUint8Vec(t *testing.T) {
func Test_doGenUint8Vec(t *testing.T) {
type args struct {
n int
dim int
Expand Down Expand Up @@ -510,7 +510,7 @@ func Test_genUint8Vec(t *testing.T) {
checkFunc = defaultCheckFunc
}

gotRet := genUint8Vec(test.args.n, test.args.dim, test.args.gen)
gotRet := doGenUint8Vec(test.args.n, test.args.dim, test.args.gen)
if err := checkFunc(test.want, gotRet); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down