refactor(wip): fix deepsource analyze
This commit is contained in:
parent
d6866b6b2e
commit
915cdb94bc
@ -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
|
||||
}
|
||||
|
||||
@ -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("<Ormer> 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))
|
||||
|
||||
@ -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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user