From 564dee9b80ffc1e406b8b91e2215d29919730ae2 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 16 Jun 2023 10:33:09 +0900 Subject: [PATCH] CI: use staticcheck (#1449) --- .github/workflows/test.yml | 8 ++++++++ auth.go | 2 +- driver_test.go | 11 +++++++---- errors.go | 2 +- infile.go | 4 ++-- nulltime.go | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2ab5e82a..3122c0e17 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,14 @@ env: MYSQL_TEST_CONCURRENT: 1 jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dominikh/staticcheck-action@v1.3.0 + with: + version: "2023.1.3" + list: runs-on: ubuntu-latest outputs: diff --git a/auth.go b/auth.go index f6b157a12..d2ab0103d 100644 --- a/auth.go +++ b/auth.go @@ -382,7 +382,7 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error { // parse public key block, rest := pem.Decode(data[1:]) if block == nil { - return fmt.Errorf("No Pem data found, data: %s", rest) + return fmt.Errorf("no pem data found, data: %s", rest) } pkix, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { diff --git a/driver_test.go b/driver_test.go index cd94c434e..c937b8416 100644 --- a/driver_test.go +++ b/driver_test.go @@ -346,8 +346,8 @@ func TestMultiQuery(t *testing.T) { rows := dbt.mustQuery("SELECT value FROM test WHERE id=1;") if rows.Next() { rows.Scan(&out) - if 5 != out { - dbt.Errorf("5 != %d", out) + if out != 5 { + dbt.Errorf("expected 5, got %d", out) } if rows.Next() { @@ -1293,7 +1293,7 @@ func TestLoadData(t *testing.T) { _, err = dbt.db.Exec("LOAD DATA LOCAL INFILE 'Reader::doesnotexist' INTO TABLE test") if err == nil { dbt.Fatal("load non-existent Reader didn't fail") - } else if err.Error() != "Reader 'doesnotexist' is not registered" { + } else if err.Error() != "reader 'doesnotexist' is not registered" { dbt.Fatal(err.Error()) } }) @@ -1401,6 +1401,7 @@ func TestReuseClosedConnection(t *testing.T) { if err != nil { t.Fatalf("error preparing statement: %s", err.Error()) } + //lint:ignore SA1019 this is a test _, err = stmt.Exec(nil) if err != nil { t.Fatalf("error executing statement: %s", err.Error()) @@ -1415,6 +1416,7 @@ func TestReuseClosedConnection(t *testing.T) { t.Errorf("panic after reusing a closed connection: %v", err) } }() + //lint:ignore SA1019 this is a test _, err = stmt.Exec(nil) if err != nil && err != driver.ErrBadConn { t.Errorf("unexpected error '%s', expected '%s'", @@ -2432,6 +2434,7 @@ func TestExecMultipleResults(t *testing.T) { t.Fatalf("failed to connect: %v", err) } conn.Raw(func(conn interface{}) error { + //lint:ignore SA1019 this is a test ex := conn.(driver.Execer) res, err := ex.Exec(` INSERT INTO test (value) VALUES ('a'), ('b'); @@ -2489,8 +2492,8 @@ func TestQueryMultipleResults(t *testing.T) { t.Fatalf("failed to connect: %v", err) } conn.Raw(func(conn interface{}) error { + //lint:ignore SA1019 this is a test qr := conn.(driver.Queryer) - c := conn.(*mysqlConn) // Demonstrate that repeated queries reset the affectedRows diff --git a/errors.go b/errors.go index 5680b6c05..a9a3060c9 100644 --- a/errors.go +++ b/errors.go @@ -21,7 +21,7 @@ var ( ErrMalformPkt = errors.New("malformed packet") ErrNoTLS = errors.New("TLS requested but server does not support TLS") ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN") - ErrNativePassword = errors.New("this user requires mysql native password authentication.") + ErrNativePassword = errors.New("this user requires mysql native password authentication") ErrOldPassword = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords") ErrUnknownPlugin = errors.New("this authentication plugin is not supported") ErrOldProtocol = errors.New("MySQL server does not support required protocol 41+") diff --git a/infile.go b/infile.go index cfd41914e..0c8af9f11 100644 --- a/infile.go +++ b/infile.go @@ -116,10 +116,10 @@ func (mc *okHandler) handleInFileRequest(name string) (err error) { defer deferredClose(&err, cl) } } else { - err = fmt.Errorf("Reader '%s' is ", name) + err = fmt.Errorf("reader '%s' is ", name) } } else { - err = fmt.Errorf("Reader '%s' is not registered", name) + err = fmt.Errorf("reader '%s' is not registered", name) } } else { // File name = strings.Trim(name, `"`) diff --git a/nulltime.go b/nulltime.go index 36c8a42c5..7d381d5c2 100644 --- a/nulltime.go +++ b/nulltime.go @@ -59,7 +59,7 @@ func (nt *NullTime) Scan(value interface{}) (err error) { } nt.Valid = false - return fmt.Errorf("Can't convert %T to time.Time", value) + return fmt.Errorf("can't convert %T to time.Time", value) } // Value implements the driver Valuer interface.