From f1112b49e52625b28e281ba2fc468b44194bc2c1 Mon Sep 17 00:00:00 2001 From: Daniel Fireman Date: Tue, 29 Mar 2022 18:26:04 -0300 Subject: [PATCH] fixing staticcheck errors --- csv/iterator_test.go | 4 ---- csv/table.go | 2 +- csv/table_test.go | 5 +---- examples/constraints/main.go | 4 +++- examples/validate/main.go | 4 +++- schema/boolean.go | 6 +++--- schema/duration.go | 2 +- schema/geopoint.go | 4 ++-- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/csv/iterator_test.go b/csv/iterator_test.go index 200e230..fb12ca7 100644 --- a/csv/iterator_test.go +++ b/csv/iterator_test.go @@ -6,10 +6,6 @@ import ( "github.com/matryer/is" ) -type iterTestValue struct { - Name string -} - const ( dontSkipHeaders = false skipHeaders = true diff --git a/csv/table.go b/csv/table.go index 03a0c99..a251da1 100644 --- a/csv/table.go +++ b/csv/table.go @@ -214,7 +214,7 @@ func Remote(url string) Source { } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) - return stringReadCloser(string(body)), nil + return stringReadCloser(string(body)), err } } diff --git a/csv/table_test.go b/csv/table_test.go index d65f25c..ff0421b 100644 --- a/csv/table_test.go +++ b/csv/table_test.go @@ -12,10 +12,6 @@ import ( "github.com/matryer/is" ) -type csvRow struct { - Name string -} - func ExampleTable_Iter() { table, _ := NewTable(FromString("\"name\"\nfoo\nbar"), LoadHeaders()) iter, _ := table.Iter() @@ -158,6 +154,7 @@ func TestReadAll(t *testing.T) { func() (io.ReadCloser, error) { return nil, errors.New("this is a source test error") }) + is.NoErr(err) _, err = table.ReadAll() is.True(err != nil) } diff --git a/examples/constraints/main.go b/examples/constraints/main.go index 637014f..a2103a6 100644 --- a/examples/constraints/main.go +++ b/examples/constraints/main.go @@ -49,7 +49,9 @@ func main() { Capital float64 URL string }{} - + if err != nil { + log.Fatalf("Error creating table: %q", err) + } if err := capitalSchema.CastTable(table, &capitals); err != nil { log.Fatalf("Error casting table: %q", err) } diff --git a/examples/validate/main.go b/examples/validate/main.go index f5049c6..0604229 100644 --- a/examples/validate/main.go +++ b/examples/validate/main.go @@ -49,7 +49,9 @@ func main() { Capital float64 URL string }{} - + if err != nil { + log.Fatalf("Error creating table: %q", err) + } iter, _ := table.Iter() for iter.Next() { if err := capitalSchema.CastRow(iter.Row(), &capitalRow); err != nil { diff --git a/schema/boolean.go b/schema/boolean.go index cc19c9b..bf93345 100644 --- a/schema/boolean.go +++ b/schema/boolean.go @@ -20,18 +20,18 @@ func castBoolean(value string, trueValues, falseValues []string) (bool, error) { } func uncastBoolean(value interface{}, trueValues, falseValues []string) (string, error) { - switch value.(type) { + switch val := value.(type) { case bool: return fmt.Sprintf("%v", value), nil case string: for _, v := range trueValues { if value == v { - return value.(string), nil + return val, nil } } for _, v := range falseValues { if value == v { - return value.(string), nil + return val, nil } } } diff --git a/schema/duration.go b/schema/duration.go index be11f59..1f539f2 100644 --- a/schema/duration.go +++ b/schema/duration.go @@ -21,7 +21,7 @@ const ( func castDuration(value string) (time.Duration, error) { matches := durationRegexp.FindStringSubmatch(value) if len(matches) == 0 { - return 0, fmt.Errorf("Invalid duration:\"%s\"", value) + return 0, fmt.Errorf("invalid duration:\"%s\"", value) } years := parseIntDuration(matches[1], hoursInYear) months := parseIntDuration(matches[2], hoursInMonth) diff --git a/schema/geopoint.go b/schema/geopoint.go index 6fc4a75..094b30f 100644 --- a/schema/geopoint.go +++ b/schema/geopoint.go @@ -32,7 +32,7 @@ func (p *GeoPoint) UnmarshalJSON(data []byte) error { return err } if a.Lon == nil || a.Lat == nil { - return fmt.Errorf("Invalid geopoint:\"%s\"", string(data)) + return fmt.Errorf("invalid geopoint:\"%s\"", string(data)) } p.Lon = *a.Lon p.Lat = *a.Lat @@ -63,7 +63,7 @@ func castGeoPoint(format, value string) (GeoPoint, error) { func applyGeoPointRegexp(r *regexp.Regexp, value string) (GeoPoint, error) { matches := r.FindStringSubmatch(value) if len(matches) == 0 || len(matches[1]) == 0 || len(matches[2]) == 0 { - return GeoPoint{}, fmt.Errorf("Invalid geopoint:\"%s\"", value) + return GeoPoint{}, fmt.Errorf("invalid geopoint:\"%s\"", value) } lon, _ := strconv.ParseFloat(matches[1], 64) lat, _ := strconv.ParseFloat(matches[2], 64)