Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
use golangci-lint and revive for linting (match main repo) (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: 6543 <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: John Olheiser <[email protected]>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/220
Reviewed-by: 6543 <[email protected]>
Reviewed-by: John Olheiser <[email protected]>
  • Loading branch information
4 people committed Jan 26, 2020
1 parent 6f491e7 commit 92f764d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions .revive.toml
Original file line number Diff line number Diff line change
@@ -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]
36 changes: 25 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,27 +25,31 @@ help:
.PHONY: clean
clean:
rm -r -f test
go clean -i ./...
$(GO) clean -i ./...

.PHONY: fmt
fmt:
find . -name "*.go" -type f ! -path "./vendor/*" ! -path "./benchmark/*" | xargs gofmt -s -w

.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
Expand All @@ -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
1 change: 1 addition & 0 deletions gitea/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 92f764d

Please sign in to comment.