enable revive linter
This commit is contained in:
		
							parent
							
								
									d49308d779
								
							
						
					
					
						commit
						aef818e0f0
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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("``")
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user