diff --git a/.golangci.yml b/.golangci.yml index 5fa5c773..ee9337be 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,6 +15,7 @@ linters: - misspell - nilerr - prealloc + - revive - unconvert - unparam issues: @@ -29,6 +30,9 @@ issues: - linters: - gocritic text: "ifElseChain" + - linters: + - revive + text: "exported" linters-settings: gci: local-prefixes: gorm.io/gorm diff --git a/finisher_api.go b/finisher_api.go index d38d60b7..7b1973cd 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -207,7 +207,7 @@ func (db *DB) FindInBatches(dest interface{}, batchSize int, fc func(tx *DB, bat return tx } -func (tx *DB) assignInterfacesToValue(values ...interface{}) { +func (db *DB) assignInterfacesToValue(values ...interface{}) { for _, value := range values { switch v := value.(type) { case []clause.Expression: @@ -215,40 +215,40 @@ func (tx *DB) assignInterfacesToValue(values ...interface{}) { if eq, ok := expr.(clause.Eq); ok { switch column := eq.Column.(type) { case string: - if field := tx.Statement.Schema.LookUpField(column); field != nil { - tx.AddError(field.Set(tx.Statement.ReflectValue, eq.Value)) + if field := db.Statement.Schema.LookUpField(column); field != nil { + db.AddError(field.Set(db.Statement.ReflectValue, eq.Value)) } case clause.Column: - if field := tx.Statement.Schema.LookUpField(column.Name); field != nil { - tx.AddError(field.Set(tx.Statement.ReflectValue, eq.Value)) + if field := db.Statement.Schema.LookUpField(column.Name); field != nil { + db.AddError(field.Set(db.Statement.ReflectValue, eq.Value)) } } } else if andCond, ok := expr.(clause.AndConditions); ok { - tx.assignInterfacesToValue(andCond.Exprs) + db.assignInterfacesToValue(andCond.Exprs) } } case clause.Expression, map[string]string, map[interface{}]interface{}, map[string]interface{}: - if exprs := tx.Statement.BuildCondition(value); len(exprs) > 0 { - tx.assignInterfacesToValue(exprs) + if exprs := db.Statement.BuildCondition(value); len(exprs) > 0 { + db.assignInterfacesToValue(exprs) } default: - if s, err := schema.Parse(value, tx.cacheStore, tx.NamingStrategy); err == nil { + if s, err := schema.Parse(value, db.cacheStore, db.NamingStrategy); err == nil { reflectValue := reflect.Indirect(reflect.ValueOf(value)) switch reflectValue.Kind() { case reflect.Struct: for _, f := range s.Fields { if f.Readable { if v, isZero := f.ValueOf(reflectValue); !isZero { - if field := tx.Statement.Schema.LookUpField(f.Name); field != nil { - tx.AddError(field.Set(tx.Statement.ReflectValue, v)) + if field := db.Statement.Schema.LookUpField(f.Name); field != nil { + db.AddError(field.Set(db.Statement.ReflectValue, v)) } } } } } } else if len(values) > 0 { - if exprs := tx.Statement.BuildCondition(values[0], values[1:]...); len(exprs) > 0 { - tx.assignInterfacesToValue(exprs) + if exprs := db.Statement.BuildCondition(values[0], values[1:]...); len(exprs) > 0 { + db.assignInterfacesToValue(exprs) } return } diff --git a/schema/schema.go b/schema/schema.go index eca113e9..2f742217 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -274,9 +274,8 @@ func ParseWithSpecialTableName(dest interface{}, cacheStore *sync.Map, namer Nam if field.DataType == "" && (field.Creatable || field.Updatable || field.Readable) { if schema.parseRelation(field); schema.err != nil { return schema, schema.err - } else { - schema.FieldsByName[field.Name] = field } + schema.FieldsByName[field.Name] = field } fieldValue := reflect.New(field.IndirectFieldType) diff --git a/tests/associations_test.go b/tests/associations_test.go index 5ce98c7d..df290693 100644 --- a/tests/associations_test.go +++ b/tests/associations_test.go @@ -180,7 +180,7 @@ func TestForeignKeyConstraintsBelongsTo(t *testing.T) { func TestFullSaveAssociations(t *testing.T) { coupon := &Coupon{ AppliesToProduct: []*CouponProduct{ - {ProductId: "full-save-association-product1"}, + {ProductID: "full-save-association-product1"}, }, AmountOff: 10, PercentOff: 0.0, diff --git a/utils/tests/dummy_dialecter.go b/utils/tests/dummy_dialecter.go index 9543f750..a187efcf 100644 --- a/utils/tests/dummy_dialecter.go +++ b/utils/tests/dummy_dialecter.go @@ -58,11 +58,11 @@ func (DummyDialector) QuoteTo(writer clause.Writer, str string) { writer.WriteByte('`') underQuoted = true if selfQuoted = continuousBacktick > 0; selfQuoted { - continuousBacktick -= 1 + continuousBacktick-- } } - for ; continuousBacktick > 0; continuousBacktick -= 1 { + for ; continuousBacktick > 0; continuousBacktick-- { writer.WriteString("``") } diff --git a/utils/tests/models.go b/utils/tests/models.go index c84f9cae..98985aed 100644 --- a/utils/tests/models.go +++ b/utils/tests/models.go @@ -63,14 +63,14 @@ type Language struct { type Coupon struct { ID int `gorm:"primarykey; size:255"` - AppliesToProduct []*CouponProduct `gorm:"foreignKey:CouponId;constraint:OnDelete:CASCADE"` + AppliesToProduct []*CouponProduct `gorm:"foreignKey:CouponID;constraint:OnDelete:CASCADE"` AmountOff uint32 `gorm:"amount_off"` PercentOff float32 `gorm:"percent_off"` } type CouponProduct struct { - CouponId int `gorm:"primarykey;size:255"` - ProductId string `gorm:"primarykey;size:255"` + CouponID int `gorm:"primarykey;size:255"` + ProductID string `gorm:"primarykey;size:255"` Desc string }