use golangci-lint and revive for linting (match main repo) #220

Merged
techknowlogick merged 7 commits from update-drone into master 2 years ago
  1. 3
      .drone.yml
  2. 25
      .revive.toml
  3. 36
      Makefile
  4. 1
      gitea/issue.go

3
.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

25
.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]

36
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

1
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 {

Loading…
Cancel
Save