From e4f4919884161156b5c63ab173357029afaced7c Mon Sep 17 00:00:00 2001 From: Matti R Date: Thu, 9 Jan 2020 14:40:33 -0500 Subject: [PATCH 1/4] use golangci-lint and revive for linting (match main repo) --- .drone.yml | 3 ++- .revive.toml | 25 +++++++++++++++++++++++++ Makefile | 30 ++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .revive.toml diff --git a/.drone.yml b/.drone.yml index 3a3126b..a211e2a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -29,7 +29,8 @@ steps: commands: - make clean - make vet - - make lint + - make golangci-lint + - make revive - make test - make build 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 ccc89ac..13299e5 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ +GO ?= go + .PHONY: all all: clean test build .PHONY: clean clean: - go clean -i ./... + $(GO) clean -i ./... .PHONY: fmt fmt: @@ -11,23 +13,35 @@ 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: - cd gitea && go test -cover -coverprofile coverage.out + cd gitea && $(GO) test -cover -coverprofile coverage.out .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.20.0; \ + fi + golangci-lint run --timeout 5m \ No newline at end of file -- 2.40.1 From 01fa02e91b09dbc25d00df3706e7f517d1783497 Mon Sep 17 00:00:00 2001 From: Matti R Date: Thu, 9 Jan 2020 14:49:14 -0500 Subject: [PATCH 2/4] update golangci-lint to 1.22.2 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 13299e5..6808c97 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,6 @@ build: 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.20.0; \ + 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 -- 2.40.1 From 439045f75122d1a46d56568bfbf6b5bfa1dcd2af Mon Sep 17 00:00:00 2001 From: Matti R Date: Sun, 26 Jan 2020 13:20:15 -0500 Subject: [PATCH 3/4] goproxy --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 185a9d2..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" -- 2.40.1 From e6f031fb126f06e20265b0e0d130e6fa7322cbfc Mon Sep 17 00:00:00 2001 From: Matti R Date: Sun, 26 Jan 2020 14:04:12 -0500 Subject: [PATCH 4/4] fix lint error --- gitea/issue.go | 1 + 1 file changed, 1 insertion(+) 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 { -- 2.40.1