diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index c6b91f0..334df6d 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -2,8 +2,6 @@ name: golangci-lint on: push: - tags: - - v* branches: - master pull_request: @@ -13,8 +11,11 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - uses: actions/checkout@v3 - name: golangci-lint - uses: golangci/golangci-lint-action@v2.5.2 + uses: golangci/golangci-lint-action@v3 with: - version: v1.38.0 + version: v1.49 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4fb2437..7782d59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: test: strategy: matrix: - go-version: [1.13.x, 1.14.x, 1.15.x, 1.16.x] + go-version: [1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x] env: GO: ${{ matrix.go-version }} runs-on: ubuntu-latest @@ -23,23 +23,23 @@ jobs: sudo cp -i cockroach-v20.1.3.linux-amd64/cockroach /usr/local/bin/ - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Cache go build cache, used to speedup go test - name: Go Build Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: $(go env GOCACHE) key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} # Cache go mod cache, used to speedup builds - name: Go Mod Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} @@ -48,7 +48,7 @@ jobs: run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... --cockroach-binary cockroach - name: Upload Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: files: ./coverage.txt flags: unittests diff --git a/.golangci.yml b/.golangci.yml index 943298e..63ff483 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,7 +2,6 @@ linters: disable-all: true enable: - bodyclose - - deadcode - dogsled - dupl - errcheck @@ -18,7 +17,6 @@ linters: - gofmt - gofumpt - goimports - - golint - gomnd - goprintffuncname - gosec @@ -30,16 +28,15 @@ linters: - nakedret - noctx - nolintlint + - revive - rowserrcheck - sqlclosecheck - staticcheck - - structcheck - stylecheck - testpackage - unconvert - unparam - unused - - varcheck - whitespace # don't enable: @@ -89,8 +86,6 @@ linters-settings: check-all: true goimports: local-prefixes: github.com/georgysavva/scany - golint: - min-confidence: 0 gomnd: settings: mnd: @@ -107,6 +102,7 @@ issues: exclude-use-default: false exclude: - "should have a package comment, unless it's in another file for this package" + - "err113: do not define dynamic errors, use wrapped static errors instead" exclude-rules: - linters: - errcheck @@ -116,6 +112,7 @@ issues: - linters: - funlen - rowserrcheck + - lll path: _test\.go max-same-issues: 0 diff --git a/dbscan/dbscan.go b/dbscan/dbscan.go index f7fcb7d..5eb0576 100644 --- a/dbscan/dbscan.go +++ b/dbscan/dbscan.go @@ -162,7 +162,7 @@ func WithAllowUnknownColumns(allowUnknownColumns bool) APIOption { // Before starting, ScanAll resets the destination slice, // so if it's not empty it will overwrite all existing elements. func (api *API) ScanAll(dst interface{}, rows Rows) error { - return api.processRows(dst, rows, true /* multipleRows */) + return api.processRows(dst, rows, true /* multipleRows. */) } // ScanOne iterates all rows to the end and makes sure that there was exactly one row @@ -171,7 +171,7 @@ func (api *API) ScanAll(dst interface{}, rows Rows) error { // and propagates any errors that could pop up. // It scans data from that single row into the destination. func (api *API) ScanOne(dst interface{}, rows Rows) error { - return api.processRows(dst, rows, false /* multipleRows */) + return api.processRows(dst, rows, false /* multipleRows. */) } // NotFound returns true if err is a not found error. @@ -190,7 +190,7 @@ type sliceDestinationMeta struct { } func (api *API) processRows(dst interface{}, rows Rows, multipleRows bool) error { - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck var sliceMeta *sliceDestinationMeta if multipleRows { var err error diff --git a/dbscan/dbscan_test.go b/dbscan/dbscan_test.go index 2a404aa..c2bd918 100644 --- a/dbscan/dbscan_test.go +++ b/dbscan/dbscan_test.go @@ -306,7 +306,7 @@ func TestScanOne_multipleRows_returnsErr(t *testing.T) { func TestScanRow(t *testing.T) { t.Parallel() rows := queryRows(t, singleRowsQuery) - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck rows.Next() expected := testModel{Foo: "foo val", Bar: "bar val"} @@ -360,7 +360,7 @@ func TestNewAPI_WithScannableTypes_InvalidInput(t *testing.T) { func TestScanRow_withAllowUnknownColumns_returnsRow(t *testing.T) { t.Parallel() rows := queryRows(t, singleRowsQuery) - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck rows.Next() got := &struct{ Foo string }{} diff --git a/dbscan/example_test.go b/dbscan/example_test.go index ebff76d..9a4598f 100644 --- a/dbscan/example_test.go +++ b/dbscan/example_test.go @@ -19,7 +19,7 @@ func ExampleScanAll() { var users []*User if err := dbscan.ScanAll(&users, rows); err != nil { - // Handle rows processing error + // Handle rows processing error. } // users variable now contains data from all rows. } @@ -111,7 +111,7 @@ func ExampleAPI() { var users []*User // Use the custom API instance to access dbscan functionality. if err := api.ScanAll(&users, rows); err != nil { - // Handle rows processing error + // Handle rows processing error. } // users variable now contains data from all rows. } diff --git a/dbscan/helpers_test.go b/dbscan/helpers_test.go index 5476689..9e5b4b1 100644 --- a/dbscan/helpers_test.go +++ b/dbscan/helpers_test.go @@ -53,7 +53,7 @@ func getAPI(opts ...dbscan.APIOption) (*dbscan.API, error) { } func scan(t *testing.T, dst interface{}, rows dbscan.Rows) error { - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck rs := testAPI.NewRowScanner(rows) rows.Next() if err := rs.Scan(dst); err != nil { diff --git a/dbscan/internal_test.go b/dbscan/internal_test.go index c38a977..2dbdaa3 100644 --- a/dbscan/internal_test.go +++ b/dbscan/internal_test.go @@ -17,7 +17,7 @@ func DoTestRowScannerStartCalledExactlyOnce(t *testing.T, api *API, queryRows qu ) AS t (foo, bar) ` rows := queryRows(t, query) - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck mockStart := &mockStartScannerFunc{} rs := api.NewRowScanner(rows) diff --git a/dbscan/rowscanner_test.go b/dbscan/rowscanner_test.go index cdc5651..60c76e4 100644 --- a/dbscan/rowscanner_test.go +++ b/dbscan/rowscanner_test.go @@ -73,7 +73,7 @@ func (cst *CustomScannableType) Scan(val interface{}) error { case string: return json.Unmarshal([]byte(v), cst) default: - return fmt.Errorf("Unsupported type: %T", v) + return fmt.Errorf("unsupported type: %T", v) } } diff --git a/sqlscan/example_test.go b/sqlscan/example_test.go index 26dfb72..42f283b 100644 --- a/sqlscan/example_test.go +++ b/sqlscan/example_test.go @@ -60,7 +60,7 @@ func ExampleScanAll() { var users []*User if err := sqlscan.ScanAll(&users, rows); err != nil { - // Handle rows processing error + // Handle rows processing error. } // users variable now contains data from all rows. } diff --git a/sqlscan/sqlscan_test.go b/sqlscan/sqlscan_test.go index 7e61b18..04ffe1a 100644 --- a/sqlscan/sqlscan_test.go +++ b/sqlscan/sqlscan_test.go @@ -144,7 +144,7 @@ func TestRowScanner_Scan(t *testing.T) { t.Parallel() rows, err := testDB.Query(singleRowsQuery) require.NoError(t, err) - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck rs := testAPI.NewRowScanner(rows) rows.Next() expected := testModel{Foo: "foo val", Bar: "bar val"} @@ -161,7 +161,7 @@ func TestScanRow(t *testing.T) { t.Parallel() rows, err := testDB.Query(singleRowsQuery) require.NoError(t, err) - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck rows.Next() expected := testModel{Foo: "foo val", Bar: "bar val"} @@ -229,7 +229,7 @@ func TestRowScanner_Scan_NULLableScannerType(t *testing.T) { t.Parallel() rows, err := testDB.Query(tc.query) require.NoError(t, err) - defer rows.Close() // nolint: errcheck + defer rows.Close() //nolint: errcheck rs := testAPI.NewRowScanner(rows) rows.Next()