added golangci (#59)

This commit is contained in:
Michał Matczuk
2018-08-07 15:30:04 +02:00
parent 2f13a81c46
commit f8424b00b9
6 changed files with 43 additions and 42 deletions

22
.golangci.yml Normal file
View File

@@ -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

View File

@@ -1,3 +1,4 @@
sudo: true
language: go language: go
go: go:
- 1.10.x - 1.10.x
@@ -9,8 +10,6 @@ env:
- DB="scylla" - DB="scylla"
- DB="cassandra" - DB="cassandra"
sudo: true
dist: trusty dist: trusty
addons: addons:
apt: apt:
@@ -21,8 +20,7 @@ before_install:
- ./.travis_start_db.sh - ./.travis_start_db.sh
install: install:
- make get-deps - make get-deps get-tools
- make get-tools
script: script:
- make - make

View File

@@ -20,3 +20,5 @@ cassandra)
;; ;;
esac esac
until nc -vz 127.0.0.1 9042; do sleep 1; done

View File

@@ -1,44 +1,28 @@
all: check test bench all: check test
ifndef GOBIN ifndef GOBIN
export GOBIN := $(GOPATH)/bin export GOBIN := $(GOPATH)/bin
endif 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 .PHONY: fmt
fmt: ## Format source code fmt:
@go fmt ./... @go fmt ./...
.PHONY: check .PHONY: check
check: ## Perform static code analysis check:
check: .check-misspell .check-lint @$(GOBIN)/golangci-lint run ./...
.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' \
./...
GOTEST := go test -cover -race -tags all GOTEST := go test -cover -race -tags all
.PHONY: test .PHONY: test
test: ## Run unit and integration tests
test: test:
@$(GOTEST) . @$(GOTEST) .
@$(GOTEST) ./migrate @$(GOTEST) ./migrate
@@ -54,12 +38,7 @@ get-deps:
go get -t ./... go get -t ./...
.PHONY: get-tools .PHONY: get-tools
get-tools: GOPATH := $(shell mktemp -d)
get-tools: get-tools:
@echo "==> Installing tools at $(GOBIN)..." @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)

View File

@@ -86,13 +86,13 @@ func createKeyspace(tb testing.TB, cluster *gocql.ClusterConfig, keyspace string
c.Timeout = 30 * time.Second c.Timeout = 30 * time.Second
session, err := c.CreateSession() session, err := c.CreateSession()
if err != nil { if err != nil {
panic(err) tb.Fatal(err)
} }
defer session.Close() defer session.Close()
err = ExecStmt(session, `DROP KEYSPACE IF EXISTS `+keyspace) err = ExecStmt(session, `DROP KEYSPACE IF EXISTS `+keyspace)
if err != nil { 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 err = ExecStmt(session, fmt.Sprintf(`CREATE KEYSPACE %s
@@ -102,7 +102,7 @@ func createKeyspace(tb testing.TB, cluster *gocql.ClusterConfig, keyspace string
}`, keyspace, *flagRF)) }`, keyspace, *flagRF))
if err != nil { if err != nil {
panic(fmt.Sprintf("unable to create keyspace: %v", err)) tb.Fatalf("unable to create keyspace: %v", err)
} }
} }

View File

@@ -244,7 +244,7 @@ type kinder interface {
// mustBe checks a value against a kind, panicing with a reflect.ValueError // mustBe checks a value against a kind, panicing with a reflect.ValueError
// if the kind isn't that which is required. // 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 { if k := v.Kind(); k != expected {
panic(&reflect.ValueError{Method: methodName(), Kind: k}) panic(&reflect.ValueError{Method: methodName(), Kind: k})
} }