Skip to content

Commit a83c173

Browse files
committed
Fix all linting issues
1 parent 72589fb commit a83c173

14 files changed

+65
-57
lines changed

doc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
// Additions include scanning into structs, named query support, rebinding
99
// queries for different drivers, convenient shorthands for common error handling
1010
// and more.
11-
//
1211
package sqlx

named.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func bindArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{
174174
arglist := make([]interface{}, 0, len(names))
175175

176176
// grab the indirected value of arg
177-
v := reflect.ValueOf(arg)
177+
var v reflect.Value
178178
for v = reflect.ValueOf(arg); v.Kind() == reflect.Ptr; {
179179
v = v.Elem()
180180
}

named_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.8
12
// +build go1.8
23

34
package sqlx

named_context_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.8
12
// +build go1.8
23

34
package sqlx
@@ -18,12 +19,12 @@ func TestNamedContextQueries(t *testing.T) {
1819
ctx := context.Background()
1920

2021
// Check that invalid preparations fail
21-
ns, err = db.PrepareNamedContext(ctx, "SELECT * FROM person WHERE first_name=:first:name")
22+
_, err = db.PrepareNamedContext(ctx, "SELECT * FROM person WHERE first_name=:first:name")
2223
if err == nil {
2324
t.Error("Expected an error with invalid prepared statement.")
2425
}
2526

26-
ns, err = db.PrepareNamedContext(ctx, "invalid sql")
27+
_, err = db.PrepareNamedContext(ctx, "invalid sql")
2728
if err == nil {
2829
t.Error("Expected an error with invalid prepared statement.")
2930
}

named_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ func TestNamedQueries(t *testing.T) {
139139
var err error
140140

141141
// Check that invalid preparations fail
142-
ns, err = db.PrepareNamed("SELECT * FROM person WHERE first_name=:first:name")
142+
_, err = db.PrepareNamed("SELECT * FROM person WHERE first_name=:first:name")
143143
if err == nil {
144144
t.Error("Expected an error with invalid prepared statement.")
145145
}
146146

147-
ns, err = db.PrepareNamed("invalid sql")
147+
_, err = db.PrepareNamed("invalid sql")
148148
if err == nil {
149149
t.Error("Expected an error with invalid prepared statement.")
150150
}

reflectx/reflect.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// allows for Go-compatible named attribute access, including accessing embedded
44
// struct attributes and the ability to use functions and struct tags to
55
// customize field names.
6-
//
76
package reflectx
87

98
import (

reflectx/reflect_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func TestFieldsEmbedded(t *testing.T) {
354354

355355
fi = fields.GetByPath("person.name")
356356
if fi == nil {
357-
t.Errorf("Expecting person.name to exist")
357+
t.Fatal("Expecting person.name to exist")
358358
}
359359
if fi.Path != "person.name" {
360360
t.Errorf("Expecting %s, got %s", "person.name", fi.Path)
@@ -365,15 +365,15 @@ func TestFieldsEmbedded(t *testing.T) {
365365

366366
fi = fields.GetByTraversal([]int{1, 0})
367367
if fi == nil {
368-
t.Errorf("Expecting traveral to exist")
368+
t.Fatal("Expecting traversal to exist")
369369
}
370370
if fi.Path != "name" {
371371
t.Errorf("Expecting %s, got %s", "name", fi.Path)
372372
}
373373

374374
fi = fields.GetByTraversal([]int{2})
375375
if fi == nil {
376-
t.Errorf("Expecting traversal to exist")
376+
t.Fatal("Expecting traversal to exist")
377377
}
378378
if _, ok := fi.Options["required"]; !ok {
379379
t.Errorf("Expecting required option to be set")
@@ -642,7 +642,6 @@ func TestMapperMethodsByName(t *testing.T) {
642642
A0 *B `db:"A0"`
643643
B `db:"A1"`
644644
A2 int
645-
a3 int
646645
}
647646

648647
val := &A{
@@ -847,22 +846,22 @@ func TestMustBe(t *testing.T) {
847846
valueErr, ok := r.(*reflect.ValueError)
848847
if !ok {
849848
t.Errorf("unexpected Method: %s", valueErr.Method)
850-
t.Error("expected panic with *reflect.ValueError")
851-
return
849+
t.Fatal("expected panic with *reflect.ValueError")
852850
}
853851
if valueErr.Method != "github.com/jmoiron/sqlx/reflectx.TestMustBe" {
852+
t.Fatalf("unexpected Method: %s", valueErr.Method)
854853
}
855854
if valueErr.Kind != reflect.String {
856-
t.Errorf("unexpected Kind: %s", valueErr.Kind)
855+
t.Fatalf("unexpected Kind: %s", valueErr.Kind)
857856
}
858857
} else {
859-
t.Error("expected panic")
858+
t.Fatal("expected panic")
860859
}
861860
}()
862861

863862
typ = reflect.TypeOf("string")
864863
mustBe(typ, reflect.Struct)
865-
t.Error("got here, didn't expect to")
864+
t.Fatal("got here, didn't expect to")
866865
}
867866

868867
type E1 struct {

sqlx.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"database/sql/driver"
66
"errors"
77
"fmt"
8-
98
"io/ioutil"
109
"path/filepath"
1110
"reflect"
@@ -51,9 +50,9 @@ func mapper() *reflectx.Mapper {
5150

5251
// isScannable takes the reflect.Type and the actual dest value and returns
5352
// whether or not it's Scannable. Something is scannable if:
54-
// * it is not a struct
55-
// * it implements sql.Scanner
56-
// * it has no exported fields
53+
// - it is not a struct
54+
// - it implements sql.Scanner
55+
// - it has no exported fields
5756
func isScannable(t reflect.Type) bool {
5857
if reflect.PtrTo(t).Implements(_scannerInterface) {
5958
return true
@@ -160,6 +159,8 @@ func mapperFor(i interface{}) *reflectx.Mapper {
160159
}
161160

162161
var _scannerInterface = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
162+
163+
//lint:ignore U1000 ignoring this for now
163164
var _valuerInterface = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
164165

165166
// Row is a reimplementation of sql.Row in order to gain access to the underlying
@@ -248,6 +249,8 @@ type DB struct {
248249

249250
// NewDb returns a new sqlx DB wrapper for a pre-existing *sql.DB. The
250251
// driverName of the original database is required for named query support.
252+
//
253+
//lint:ignore ST1003 changing this would break the package interface.
251254
func NewDb(db *sql.DB, driverName string) *DB {
252255
return &DB{DB: db, driverName: driverName, Mapper: mapper()}
253256
}
@@ -884,9 +887,9 @@ func structOnlyError(t reflect.Type) error {
884887
// then each row must only have one column which can scan into that type. This
885888
// allows you to do something like:
886889
//
887-
// rows, _ := db.Query("select id from people;")
888-
// var ids []int
889-
// scanAll(rows, &ids, false)
890+
// rows, _ := db.Query("select id from people;")
891+
// var ids []int
892+
// scanAll(rows, &ids, false)
890893
//
891894
// and ids will be a list of the id results. I realize that this is a desirable
892895
// interface to expose to users, but for now it will only be exposed via changes
@@ -935,9 +938,9 @@ func scanAll(rows rowsi, dest interface{}, structOnly bool) error {
935938
var values []interface{}
936939
var m *reflectx.Mapper
937940

938-
switch rows.(type) {
941+
switch rows := rows.(type) {
939942
case *Rows:
940-
m = rows.(*Rows).Mapper
943+
m = rows.Mapper
941944
default:
942945
m = mapper()
943946
}

sqlx_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.8
12
// +build go1.8
23

34
package sqlx

sqlx_context_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
//go:build go1.8
12
// +build go1.8
23

34
// The following environment variables, if set, will be used:
45
//
5-
// * SQLX_SQLITE_DSN
6-
// * SQLX_POSTGRES_DSN
7-
// * SQLX_MYSQL_DSN
6+
// - SQLX_SQLITE_DSN
7+
// - SQLX_POSTGRES_DSN
8+
// - SQLX_MYSQL_DSN
89
//
910
// Set any of these variables to 'skip' to skip them. Note that for MySQL,
1011
// the string '?parseTime=True' will be appended to the DSN if it's not there
1112
// already.
12-
//
1313
package sqlx
1414

1515
import (
@@ -23,9 +23,10 @@ import (
2323
"time"
2424

2525
_ "github.com/go-sql-driver/mysql"
26-
"github.com/jmoiron/sqlx/reflectx"
2726
_ "github.com/lib/pq"
2827
_ "github.com/mattn/go-sqlite3"
28+
29+
"github.com/jmoiron/sqlx/reflectx"
2930
)
3031

3132
func MultiExecContext(ctx context.Context, e ExecerContext, query string) {
@@ -92,7 +93,7 @@ func TestMissingNamesContextContext(t *testing.T) {
9293
FirstName string `db:"first_name"`
9394
LastName string `db:"last_name"`
9495
Email string
95-
//AddedAt time.Time `db:"added_at"`
96+
// AddedAt time.Time `db:"added_at"`
9697
}
9798

9899
// test Select first
@@ -485,7 +486,7 @@ func TestNamedQueryContext(t *testing.T) {
485486
// these are tests for #73; they verify that named queries work if you've
486487
// changed the db mapper. This code checks both NamedQuery "ad-hoc" style
487488
// queries and NamedStmt queries, which use different code paths internally.
488-
old := *db.Mapper
489+
old := (*db).Mapper
489490

490491
type JSONPerson struct {
491492
FirstName sql.NullString `json:"FIRST"`
@@ -570,7 +571,7 @@ func TestNamedQueryContext(t *testing.T) {
570571

571572
check(t, rows)
572573

573-
db.Mapper = &old
574+
db.Mapper = old
574575

575576
// Test nested structs
576577
type Place struct {
@@ -831,7 +832,7 @@ func TestUsageContext(t *testing.T) {
831832
if err != nil {
832833
t.Error(err)
833834
}
834-
//fmt.Printf("%#v\n%#v\n%#v\n", placesptr[0], placesptr[1], placesptr[2])
835+
// fmt.Printf("%#v\n%#v\n%#v\n", placesptr[0], placesptr[1], placesptr[2])
835836

836837
// if you have null fields and use SELECT *, you must use sql.Null* in your struct
837838
// this test also verifies that you can use either a []Struct{} or a []*Struct{}
@@ -1274,9 +1275,9 @@ func TestInContext(t *testing.T) {
12741275
}
12751276
RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) {
12761277
loadDefaultFixtureContext(ctx, db, t)
1277-
//tx.MustExecContext(ctx, tx.Rebind("INSERT INTO place (country, city, telcode) VALUES (?, ?, ?)"), "United States", "New York", "1")
1278-
//tx.MustExecContext(ctx, tx.Rebind("INSERT INTO place (country, telcode) VALUES (?, ?)"), "Hong Kong", "852")
1279-
//tx.MustExecContext(ctx, tx.Rebind("INSERT INTO place (country, telcode) VALUES (?, ?)"), "Singapore", "65")
1278+
// tx.MustExecContext(ctx, tx.Rebind("INSERT INTO place (country, city, telcode) VALUES (?, ?, ?)"), "United States", "New York", "1")
1279+
// tx.MustExecContext(ctx, tx.Rebind("INSERT INTO place (country, telcode) VALUES (?, ?)"), "Hong Kong", "852")
1280+
// tx.MustExecContext(ctx, tx.Rebind("INSERT INTO place (country, telcode) VALUES (?, ?)"), "Singapore", "65")
12801281
telcodes := []int{852, 65}
12811282
q := "SELECT * FROM place WHERE telcode IN(?) ORDER BY telcode"
12821283
query, args, err := In(q, telcodes)
@@ -1355,7 +1356,7 @@ func TestConn(t *testing.T) {
13551356

13561357
RunWithSchemaContext(context.Background(), schema, t, func(ctx context.Context, db *DB, t *testing.T) {
13571358
conn, err := db.Connx(ctx)
1358-
defer conn.Close()
1359+
defer conn.Close() //lint:ignore SA5001 it's OK to ignore this here.
13591360
if err != nil {
13601361
t.Fatal(err)
13611362
}

0 commit comments

Comments
 (0)