use golangci-lint and revive for linting (match main repo) (#220)
Co-authored-by: 6543 <6543@noreply.gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/220 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: John Olheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
6f491e70ae
commit
92f764ddf4
4 changed files with 53 additions and 12 deletions
|
@ -34,7 +34,7 @@ steps:
|
||||||
pull: always
|
pull: always
|
||||||
image: golang:1.13
|
image: golang:1.13
|
||||||
environment:
|
environment:
|
||||||
GOPROXY: https://goproxy.cn
|
GOPROXY: https://goproxy.cn,direct
|
||||||
HTTP_PROXY: ""
|
HTTP_PROXY: ""
|
||||||
GITEA_SDK_TEST_URL: "http://gitea:3000"
|
GITEA_SDK_TEST_URL: "http://gitea:3000"
|
||||||
GITEA_SDK_TEST_USERNAME: "test01"
|
GITEA_SDK_TEST_USERNAME: "test01"
|
||||||
|
@ -43,6 +43,7 @@ steps:
|
||||||
commands:
|
commands:
|
||||||
- make clean
|
- make clean
|
||||||
- make vet
|
- make vet
|
||||||
|
- make revive
|
||||||
- make build
|
- make build
|
||||||
- curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance
|
- curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance
|
||||||
- make test
|
- make test
|
||||||
|
|
25
.revive.toml
Normal file
25
.revive.toml
Normal file
|
@ -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
Makefile
36
Makefile
|
@ -1,8 +1,10 @@
|
||||||
|
GO ?= go
|
||||||
|
|
||||||
WORK_DIR := $(shell pwd)
|
WORK_DIR := $(shell pwd)
|
||||||
|
|
||||||
export GITEA_SDK_TEST_URL ?= http://localhost:3000
|
GITEA_SDK_TEST_URL ?= http://localhost:3000
|
||||||
export GITEA_SDK_TEST_USERNAME ?= test01
|
GITEA_SDK_TEST_USERNAME ?= test01
|
||||||
export GITEA_SDK_TEST_PASSWORD ?= test01
|
GITEA_SDK_TEST_PASSWORD ?= test01
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: clean test build
|
all: clean test build
|
||||||
|
@ -23,7 +25,7 @@ help:
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -r -f test
|
rm -r -f test
|
||||||
go clean -i ./...
|
$(GO) clean -i ./...
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
|
@ -31,19 +33,23 @@ fmt:
|
||||||
|
|
||||||
.PHONY: vet
|
.PHONY: vet
|
||||||
vet:
|
vet:
|
||||||
cd gitea && go vet ./...
|
cd gitea && $(GO) vet ./...
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
|
@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.'
|
||||||
go get -u golang.org/x/lint/golint; \
|
|
||||||
|
.PHONY: revive
|
||||||
|
revive:
|
||||||
|
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
$(GO) get -u github.com/mgechev/revive; \
|
||||||
fi
|
fi
|
||||||
cd gitea && golint -set_exit_status
|
revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
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 \
|
@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
|
fi
|
||||||
|
|
||||||
.PHONY: test-instance
|
.PHONY: test-instance
|
||||||
|
@ -67,8 +73,16 @@ test-instance:
|
||||||
|
|
||||||
.PHONY: bench
|
.PHONY: bench
|
||||||
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
|
.PHONY: build
|
||||||
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
|
|
@ -52,6 +52,7 @@ type ListIssueOption struct {
|
||||||
KeyWord string
|
KeyWord string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryEncode turns options into querystring argument
|
||||||
func (opt *ListIssueOption) QueryEncode() string {
|
func (opt *ListIssueOption) QueryEncode() string {
|
||||||
query := make(url.Values)
|
query := make(url.Values)
|
||||||
if opt.Page > 0 {
|
if opt.Page > 0 {
|
||||||
|
|
Loading…
Reference in a new issue