Skip to content

Commit

Permalink
Make lint and fix linter issues (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
theruziev authored and thedevsaddam committed Apr 13, 2019
1 parent e1d194f commit e9675d5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 29 deletions.
9 changes: 1 addition & 8 deletions roller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *roller) getFlatMap() map[string]interface{} {
return r.root
}

// getFlatVal return interfac{} value if exist
// getFlatVal return interface{} value if exist
func (r *roller) getFlatVal(key string) (interface{}, bool) {
var val interface{}
var ok bool
Expand Down Expand Up @@ -173,13 +173,6 @@ func (r *roller) traverseStruct(iface interface{}) {

// traverseMap through all the map and add it to root
func (r *roller) traverseMap(iface interface{}) {
ifv := reflect.ValueOf(iface)
ift := reflect.TypeOf(iface)
if ift.Kind() == reflect.Ptr {
ifv = ifv.Elem()
ift = ift.Elem()
}

switch t := iface.(type) {
case map[string]interface{}:
for k, v := range t {
Expand Down
5 changes: 3 additions & 2 deletions roller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package govalidator

import (
"reflect"
"testing"
)

Expand Down Expand Up @@ -117,7 +118,7 @@ func BenchmarkRoller_Start(b *testing.B) {

func Test_Roller_Start_empty_map(t *testing.T) {
r := roller{}
emap := make(map[string]interface{}, 0)
emap := make(map[string]interface{})
r.setTagIdentifier("validate")
r.setTagSeparator("|")
r.start(emap)
Expand Down Expand Up @@ -242,7 +243,7 @@ func TestRoller_GetFlatVal(t *testing.T) {

//check struct field with array
intArrOf5, _ := r.getFlatVal("array")
if len(intArrOf5.([5]int)) != 5 {
if reflect.ValueOf(intArrOf5).Len() != 5 && reflect.TypeOf(intArrOf5).Kind() == reflect.Array {
t.Error("GetFlatVal failed for struct array of [5]int field!")
}

Expand Down
10 changes: 5 additions & 5 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var null = []byte("null")

// UnmarshalJSON ...
func (i *Int) UnmarshalJSON(data []byte) error {
if bytes.Compare(data, null) == 0 {
if bytes.Equal(data, null) {
return nil
}
i.IsSet = true
Expand All @@ -40,7 +40,7 @@ type Int64 struct {

// UnmarshalJSON ...
func (i *Int64) UnmarshalJSON(data []byte) error {
if bytes.Compare(data, null) == 0 {
if bytes.Equal(data, null) {
return nil
}
i.IsSet = true
Expand All @@ -65,7 +65,7 @@ type Float32 struct {

// UnmarshalJSON ...
func (i *Float32) UnmarshalJSON(data []byte) error {
if bytes.Compare(data, null) == 0 {
if bytes.Equal(data, null) {
return nil
}
i.IsSet = true
Expand All @@ -90,7 +90,7 @@ type Float64 struct {

// UnmarshalJSON ...
func (i *Float64) UnmarshalJSON(data []byte) error {
if bytes.Compare(data, null) == 0 {
if bytes.Equal(data, null) {
return nil
}
i.IsSet = true
Expand All @@ -115,7 +115,7 @@ type Bool struct {

// UnmarshalJSON ...
func (i *Bool) UnmarshalJSON(data []byte) error {
if bytes.Compare(data, null) == 0 {
if bytes.Equal(data, null) {
return nil
}
i.IsSet = true
Expand Down
10 changes: 0 additions & 10 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ func Benchmark_isContainRequiredField(b *testing.B) {
}
}

type person struct{}

func (person) Details() string {
return "John Doe"
}

func (person) Age(age string) string {
return "Age: " + age
}

func Test_isRuleExist(t *testing.T) {
if !isRuleExist("required") {
t.Error("isRuleExist failed for valid rule")
Expand Down
4 changes: 2 additions & 2 deletions validate_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func buildMocFormReq() (*http.Request, error) {
if err != nil {
return nil, err
}
io.Copy(part, file)
file.Close()
_, _ = io.Copy(part, file)
_ = file.Close()
err = writer.Close()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func (v *Validator) Validate() url.Values {
// and if the input data is empty for this field
func (v *Validator) getNonRequiredFields() map[string]struct{} {
if v.Opts.FormSize > 0 {
v.Opts.Request.ParseMultipartForm(v.Opts.FormSize)
_ = v.Opts.Request.ParseMultipartForm(v.Opts.FormSize)
} else {
v.Opts.Request.ParseMultipartForm(defaultFormSize)
_ = v.Opts.Request.ParseMultipartForm(defaultFormSize)
}

inputs := v.Opts.Request.Form
Expand Down

0 comments on commit e9675d5

Please sign in to comment.