From 92f764ddf4916e50f48a9c144a3eca2893658dfb Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sun, 26 Jan 2020 19:08:47 +0000 Subject: [PATCH] use golangci-lint and revive for linting (match main repo) (#220) Co-authored-by: 6543 <6543@noreply.gitea.io> Co-authored-by: Lunny Xiao Co-authored-by: John Olheiser Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/220 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: John Olheiser --- .drone.yml | 3 ++- .revive.toml | 25 +++++++++++++++++++++++++ Makefile | 36 +++++++++++++++++++++++++----------- gitea/issue.go | 1 + 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 .revive.toml diff --git a/.drone.yml b/.drone.yml index 6cb9997..3212cb2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -34,7 +34,7 @@ steps: pull: always image: golang:1.13 environment: - GOPROXY: https://goproxy.cn + GOPROXY: https://goproxy.cn,direct HTTP_PROXY: "" GITEA_SDK_TEST_URL: "http://gitea:3000" GITEA_SDK_TEST_USERNAME: "test01" @@ -43,6 +43,7 @@ steps: commands: - make clean - make vet + - make revive - make build - curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance - make test diff --git a/.revive.toml b/.revive.toml new file mode 100644 index 0000000..74743d5 --- /dev/null +++ b/.revive.toml @@ -0,0 +1,25 @@ +ignoreGeneratedHeader = false +severity = "warning" +confidence = 0.8 +errorCode = 1 +warningCode = 1 + +[rule.blank-imports] +[rule.context-as-argument] +[rule.context-keys-type] +[rule.dot-imports] +[rule.error-return] +[rule.error-strings] +[rule.error-naming] +[rule.exported] +[rule.if-return] +[rule.increment-decrement] +[rule.var-naming] +[rule.var-declaration] +[rule.package-comments] +[rule.range] +[rule.receiver-naming] +[rule.time-naming] +[rule.unexported-return] +[rule.indent-error-flow] +[rule.errorf] diff --git a/Makefile b/Makefile index 51876aa..f574f47 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ +GO ?= go + WORK_DIR := $(shell pwd) -export GITEA_SDK_TEST_URL ?= http://localhost:3000 -export GITEA_SDK_TEST_USERNAME ?= test01 -export GITEA_SDK_TEST_PASSWORD ?= test01 +GITEA_SDK_TEST_URL ?= http://localhost:3000 +GITEA_SDK_TEST_USERNAME ?= test01 +GITEA_SDK_TEST_PASSWORD ?= test01 .PHONY: all all: clean test build @@ -23,7 +25,7 @@ help: .PHONY: clean clean: rm -r -f test - go clean -i ./... + $(GO) clean -i ./... .PHONY: fmt fmt: @@ -31,19 +33,23 @@ fmt: .PHONY: vet vet: - cd gitea && go vet ./... + cd gitea && $(GO) vet ./... .PHONY: lint lint: - @which golint > /dev/null; if [ $$? -ne 0 ]; then \ - go get -u golang.org/x/lint/golint; \ + @echo 'make lint is depricated. Use "make revive" if you want to use the old lint tool, or "make golangci-lint" to run a complete code check.' + +.PHONY: revive +revive: + @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GO) get -u github.com/mgechev/revive; \ fi - cd gitea && golint -set_exit_status + revive -config .revive.toml -exclude=./vendor/... ./... || exit 1 .PHONY: test test: @if [ -z "$(shell curl --noproxy "*" "${GITEA_SDK_TEST_URL}/api/v1/version" 2> /dev/null)" ]; then \echo "No test-instance detected!"; exit 1; else \ - cd gitea && go test -cover -coverprofile coverage.out; \ + cd gitea && $(GO) test -cover -coverprofile coverage.out; \ fi .PHONY: test-instance @@ -67,8 +73,16 @@ test-instance: .PHONY: bench bench: - cd gitea && go test -run=XXXXXX -benchtime=10s -bench=. || exit 1 + cd gitea && $(GO) test -run=XXXXXX -benchtime=10s -bench=. || exit 1 .PHONY: build build: - cd gitea && go build + cd gitea && $(GO) build + +.PHONY: golangci-lint +golangci-lint: + @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + export BINARY="golangci-lint"; \ + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.22.2; \ + fi + golangci-lint run --timeout 5m \ No newline at end of file diff --git a/gitea/issue.go b/gitea/issue.go index a6e42e1..73243ee 100644 --- a/gitea/issue.go +++ b/gitea/issue.go @@ -52,6 +52,7 @@ type ListIssueOption struct { KeyWord string } +// QueryEncode turns options into querystring argument func (opt *ListIssueOption) QueryEncode() string { query := make(url.Values) if opt.Page > 0 {