From 915cdb94bcd91aa502f0dd5c806ac0df64e0ee1a Mon Sep 17 00:00:00 2001 From: Cr <631807682@qq.com> Date: Mon, 6 Sep 2021 16:04:03 +0800 Subject: [PATCH] refactor(wip): fix deepsource analyze --- client/orm/filter_orm_decorator.go | 2 +- client/orm/orm.go | 6 +++--- client/orm/orm_test.go | 12 ++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/client/orm/filter_orm_decorator.go b/client/orm/filter_orm_decorator.go index ed7dd48f..edeaaade 100644 --- a/client/orm/filter_orm_decorator.go +++ b/client/orm/filter_orm_decorator.go @@ -518,7 +518,7 @@ func (f *filterOrmDecorator) RollbackUnlessCommit() error { return f.convertError(res[0]) } -func (f *filterOrmDecorator) convertError(v interface{}) error { +func (*filterOrmDecorator) convertError(v interface{}) error { if v == nil { return nil } diff --git a/client/orm/orm.go b/client/orm/orm.go index fb19bf9e..a87e23ad 100644 --- a/client/orm/orm.go +++ b/client/orm/orm.go @@ -108,7 +108,7 @@ var ( ) // get model info and model reflect value -func (o *ormBase) getMiInd(md interface{}, needPtr bool) (mi *modelInfo, ind reflect.Value) { +func (*ormBase) getMiInd(md interface{}, needPtr bool) (mi *modelInfo, ind reflect.Value) { val := reflect.ValueOf(md) ind = reflect.Indirect(val) typ := ind.Type() @@ -123,7 +123,7 @@ func (o *ormBase) getMiInd(md interface{}, needPtr bool) (mi *modelInfo, ind ref } // get field info from model info by given field name -func (o *ormBase) getFieldInfo(mi *modelInfo, name string) *fieldInfo { +func (*ormBase) getFieldInfo(mi *modelInfo, name string) *fieldInfo { fi, ok := mi.fields.GetByAny(name) if !ok { panic(fmt.Errorf(" cannot find field `%s` for model `%s`", name, mi.fullName)) @@ -196,7 +196,7 @@ func (o *ormBase) InsertWithCtx(ctx context.Context, md interface{}) (int64, err } // set auto pk field -func (o *ormBase) setPk(mi *modelInfo, ind reflect.Value, id int64) { +func (*ormBase) setPk(mi *modelInfo, ind reflect.Value, id int64) { if mi.fields.pk.auto { if mi.fields.pk.fieldType&IsPositiveIntegerField > 0 { ind.FieldByIndex(mi.fields.pk.fieldIndex).SetUint(uint64(id)) diff --git a/client/orm/orm_test.go b/client/orm/orm_test.go index 2bb89ab5..81fbf2b5 100644 --- a/client/orm/orm_test.go +++ b/client/orm/orm_test.go @@ -129,7 +129,7 @@ func getCaller(skip int) string { if cur == line { flag = ">>" } - ls := strings.Replace(string(lines[o+i]), "\t", " ", -1) + ls := formatLines(string(lines[o+i])) code := fmt.Sprintf(" %s %5d: %s", flag, cur, ls) if code != "" { codes = append(codes, code) @@ -143,6 +143,10 @@ func getCaller(skip int) string { return fmt.Sprintf("%s:%s:%d: \n%s", fn, funName, line, strings.Join(codes, "\n")) } +func formatLines(s string) string { + return strings.Replace(s, "\t", " ", -1) +} + // Deprecated: Using stretchr/testify/assert func throwFail(t *testing.T, err error, args ...interface{}) { if err != nil { @@ -213,7 +217,7 @@ func TestSyncDb(t *testing.T) { modelCache.clean() } -func TestRegisterModels(t *testing.T) { +func TestRegisterModels(_ *testing.T) { RegisterModel(new(Data), new(DataNull), new(DataCustom)) RegisterModel(new(User)) RegisterModel(new(Profile)) @@ -246,10 +250,10 @@ func TestModelSyntax(t *testing.T) { user := &User{} ind := reflect.ValueOf(user).Elem() fn := getFullName(ind.Type()) - mi, ok := modelCache.getByFullName(fn) + _, ok := modelCache.getByFullName(fn) throwFail(t, AssertIs(ok, true)) - mi, ok = modelCache.get("user") + mi, ok := modelCache.get("user") throwFail(t, AssertIs(ok, true)) if ok { throwFail(t, AssertIs(mi.fields.GetByName("ShouldSkip") == nil, true))