diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b77191b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,22 @@ +run: + deadline: 5m + tests: false + silent: true + +linters-settings: + lll: + line-length: 180 + +linters: + enable-all: true + disable: + - gas + - interfacer + - maligned + - nakedret + +issues: + exclude-use-default: false + exclude: + - composite literal uses unkeyed fields + - Error return value of `.+\.Close` is not checked diff --git a/.travis.yml b/.travis.yml index 84279f4..12b24b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: true language: go go: - 1.10.x @@ -9,8 +10,6 @@ env: - DB="scylla" - DB="cassandra" -sudo: true - dist: trusty addons: apt: @@ -21,8 +20,7 @@ before_install: - ./.travis_start_db.sh install: - - make get-deps - - make get-tools + - make get-deps get-tools script: - make diff --git a/.travis_start_db.sh b/.travis_start_db.sh index f1e68ae..0df92da 100755 --- a/.travis_start_db.sh +++ b/.travis_start_db.sh @@ -20,3 +20,5 @@ cassandra) ;; esac + +until nc -vz 127.0.0.1 9042; do sleep 1; done diff --git a/Makefile b/Makefile index a329916..6ebb043 100644 --- a/Makefile +++ b/Makefile @@ -1,44 +1,28 @@ -all: check test bench +all: check test ifndef GOBIN export GOBIN := $(GOPATH)/bin endif +define dl + @curl -sSq -L $(2) -o $(GOBIN)/$(1) && chmod u+x $(GOBIN)/$(1) +endef + +define dl_tgz + @curl -sSq -L $(2) | tar zxf - --strip 1 -C $(GOBIN) --wildcards '*/$(1)' +endef + .PHONY: fmt -fmt: ## Format source code +fmt: @go fmt ./... .PHONY: check -check: ## Perform static code analysis -check: .check-misspell .check-lint - -.PHONY: .check-fmt -.check-fmt: - @go fmt ./... | tee /dev/stderr | ifne false - -.PHONY: .check-misspell -.check-misspell: - @$(GOBIN)/misspell ./... - -.PHONY: .check-lint -.check-lint: - @$(GOBIN)/golangci-lint run -s --disable-all -E govet -E errcheck -E staticcheck \ - -E gas -E typecheck -E unused -E structcheck -E varcheck -E ineffassign -E deadcode \ - -E gofmt -E golint -E gosimple -E unconvert -E dupl -E depguard -E gocyclo \ - --tests=false \ - --exclude-use-default=false \ - --exclude='composite literal uses unkeyed fields' \ - --exclude='Error return value of `.+\.Close` is not checked' \ - --exclude='G104' \ - --exclude='G304' \ - --exclude='G401' \ - --exclude='G501' \ - ./... +check: + @$(GOBIN)/golangci-lint run ./... GOTEST := go test -cover -race -tags all .PHONY: test -test: ## Run unit and integration tests test: @$(GOTEST) . @$(GOTEST) ./migrate @@ -54,12 +38,7 @@ get-deps: go get -t ./... .PHONY: get-tools -get-tools: GOPATH := $(shell mktemp -d) get-tools: @echo "==> Installing tools at $(GOBIN)..." - @mkdir -p $(GOBIN) + @$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v1.9.3/golangci-lint-1.9.3-linux-amd64.tar.gz) - @go get -u github.com/client9/misspell/cmd/misspell - @go get -u github.com/golangci/golangci-lint/cmd/golangci-lint - - @rm -Rf $(GOPATH) diff --git a/gocqlxtest/gocqlxtest.go b/gocqlxtest/gocqlxtest.go index 4950946..5725d62 100644 --- a/gocqlxtest/gocqlxtest.go +++ b/gocqlxtest/gocqlxtest.go @@ -86,13 +86,13 @@ func createKeyspace(tb testing.TB, cluster *gocql.ClusterConfig, keyspace string c.Timeout = 30 * time.Second session, err := c.CreateSession() if err != nil { - panic(err) + tb.Fatal(err) } defer session.Close() err = ExecStmt(session, `DROP KEYSPACE IF EXISTS `+keyspace) if err != nil { - panic(fmt.Sprintf("unable to drop keyspace: %v", err)) + tb.Fatalf("unable to drop keyspace: %v", err) } err = ExecStmt(session, fmt.Sprintf(`CREATE KEYSPACE %s @@ -102,7 +102,7 @@ func createKeyspace(tb testing.TB, cluster *gocql.ClusterConfig, keyspace string }`, keyspace, *flagRF)) if err != nil { - panic(fmt.Sprintf("unable to create keyspace: %v", err)) + tb.Fatalf("unable to create keyspace: %v", err) } } diff --git a/reflectx/reflect.go b/reflectx/reflect.go index 4d1588d..659782e 100644 --- a/reflectx/reflect.go +++ b/reflectx/reflect.go @@ -244,7 +244,7 @@ type kinder interface { // mustBe checks a value against a kind, panicing with a reflect.ValueError // if the kind isn't that which is required. -func mustBe(v kinder, expected reflect.Kind) { +func mustBe(v kinder, expected reflect.Kind) { // nolint: unparam if k := v.Kind(); k != expected { panic(&reflect.ValueError{Method: methodName(), Kind: k}) }