diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a4d8c1..4a6181e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,8 @@ jobs: run: go vet ./... - name: Check go version run: go version - - name: Run golint - run: go get golang.org/x/lint/golint && bash -c "$(go env GOPATH)/bin/golint -set_exit_status -min_confidence 0.9 ./..." + - name: Run linters + run: go install honnef.co/go/tools/cmd/staticcheck@latest && bash -c "$(go env GOPATH)/bin/staticcheck ./..." - name: Run Tests run: ./scripts/run-all-tests.sh - name: Run Coverage diff --git a/Makefile b/Makefile index 6090584..4c3285e 100644 --- a/Makefile +++ b/Makefile @@ -18,22 +18,22 @@ bench: @echo "Benchmark executed on commit: $$(git rev-parse HEAD)" lint: setup - @$(GOBIN)/golint -set_exit_status -min_confidence 0.9 $(path) $(args) + @$(GOBIN)/staticcheck $(path) $(args) @go vet $(path) $(args) @make --no-print-directory -C benchmarks - @echo "Golint & Go Vet found no problems on your code!" + @echo "StaticCheck & Go Vet found no problems on your code!" gen: mock mock: setup $(GOBIN)/mockgen -package=exampleservice -source=contracts.go -destination=examples/example_service/mocks.go -setup: $(GOBIN)/richgo $(GOBIN)/golint $(GOBIN)/mockgen +setup: $(GOBIN)/richgo $(GOBIN)/staticcheck $(GOBIN)/mockgen $(GOBIN)/richgo: go get github.com/kyoh86/richgo -$(GOBIN)/golint: - go get golang.org/x/lint +$(GOBIN)/staticcheck: + go install honnef.co/go/tools/cmd/staticcheck@latest $(GOBIN)/mockgen: @# (Gomock is used on examples/example_service) diff --git a/benchmarks/Makefile b/benchmarks/Makefile index 6f20d82..6727783 100644 --- a/benchmarks/Makefile +++ b/benchmarks/Makefile @@ -2,5 +2,5 @@ GOBIN=$(shell go env GOPATH)/bin lint: - @$(GOBIN)/golint -set_exit_status -min_confidence 0.9 ./... + @$(GOBIN)/staticcheck ./... @go vet ./... diff --git a/ksql.go b/ksql.go index fb50cc7..a840946 100644 --- a/ksql.go +++ b/ksql.go @@ -495,7 +495,7 @@ func (c DB) insertWithLastInsertID( if !tID.ConvertibleTo(fieldType) { return fmt.Errorf( - "Can't convert last insert id of type int64 into field `%s` of type %v", + "can't convert last insert id of type int64 into field `%s` of type %v", idName, fieldType, ) diff --git a/ksqltest/testhelpers_test.go b/ksqltest/testhelpers_test.go index a678177..6dda318 100644 --- a/ksqltest/testhelpers_test.go +++ b/ksqltest/testhelpers_test.go @@ -381,11 +381,6 @@ func TestCallFunctionWithRows(t *testing.T) { }) t.Run("should report error if the input function is invalid", func(t *testing.T) { - type User struct { - Name string `ksql:"name"` - Age int `ksql:"age"` - } - err := CallFunctionWithRows(func() {}, []map[string]interface{}{{ "name": "fake-name1", "age": 42, diff --git a/kstructs/testhelpers_test.go b/kstructs/testhelpers_test.go index 4f91227..92f12bf 100644 --- a/kstructs/testhelpers_test.go +++ b/kstructs/testhelpers_test.go @@ -381,11 +381,6 @@ func TestCallFunctionWithRows(t *testing.T) { }) t.Run("should report error if the input function is invalid", func(t *testing.T) { - type User struct { - Name string `ksql:"name"` - Age int `ksql:"age"` - } - err := CallFunctionWithRows(func() {}, []map[string]interface{}{{ "name": "fake-name1", "age": 42, diff --git a/main_test.go b/main_test.go deleted file mode 100644 index e0cb1e2..0000000 --- a/main_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package ksql - -import ( - "encoding/json" - "fmt" -) - -func toJSON(i interface{}) []byte { - rawJSON, err := json.Marshal(i) - if err != nil { - panic(fmt.Sprintf("error marshalling %v during test", i)) - } - return rawJSON -} diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 0000000..c8fe791 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1 @@ +checks = ["all","-S1002","-ST1000","-ST1003"] diff --git a/test_adapters.go b/test_adapters.go index 7596e26..23603cb 100644 --- a/test_adapters.go +++ b/test_adapters.go @@ -37,8 +37,6 @@ type address struct { Country string `json:"country"` } -var postsTable = NewTable("posts") - type post struct { ID int `ksql:"id"` UserID uint `ksql:"user_id"` @@ -1936,7 +1934,6 @@ func QueryChunksTest( return nil }, func(missingReturnType []user) { - return }, func(users []user) string { return "" @@ -2348,47 +2345,6 @@ func shiftErrSlice(errs *[]error) error { return err } -func getUsersByID(db DBAdapter, dialect Dialect, resultsPtr *[]user, ids ...uint) error { - placeholders := make([]string, len(ids)) - params := make([]interface{}, len(ids)) - for i := range ids { - params[i] = ids[i] - placeholders[i] = dialect.Placeholder(i) - } - - results := []user{} - rows, err := db.QueryContext( - context.TODO(), - fmt.Sprintf( - "SELECT id, name, age FROM users WHERE id IN (%s)", - strings.Join(placeholders, ", "), - ), - params..., - ) - if err != nil { - return err - } - defer rows.Close() - - for rows.Next() { - var u user - err = rows.Scan(&u.ID, &u.Name, &u.Age) - if err != nil { - return err - } - results = append(results, u) - } - if rows.Err() != nil { - return rows.Err() - } - if err := rows.Close(); err != nil { - return err - } - - *resultsPtr = results - return nil -} - func getUserByID(db DBAdapter, dialect Dialect, result *user, id uint) error { rows, err := db.QueryContext(context.TODO(), `SELECT id, name, age, address FROM users WHERE id=`+dialect.Placeholder(0), id) if err != nil {