diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..dd0fc13 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,45 @@ +--- +kind: pipeline +name: compliance + +platform: + os: linux + arch: arm64 + +trigger: + event: + - pull_request + +steps: + - name: check + pull: always + image: golang:1.14 + environment: + GOPROXY: https://goproxy.cn + commands: + - make build + - make lint + - make vet + +--- +kind: pipeline +name: build-master + +platform: + os: linux + arch: amd64 + +trigger: + branch: + - master + event: + - push + +steps: + - name: build + pull: always + image: techknowlogick/xgo:latest + environment: + GOPROXY: https://goproxy.cn + commands: + - make build \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..704d99a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,23 @@ +linters: + enable: + - deadcode + - dogsled + - dupl + - errcheck + - gocognit + - goconst + - gocritic + - gocyclo + - gofmt + - golint + - gosimple + - govet + - maligned + - misspell + - prealloc + - staticcheck + - structcheck + - typecheck + - unparam + - unused + - varcheck \ No newline at end of file diff --git a/Makefile b/Makefile index 5305662..e9c9f4f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,22 @@ +GO ?= go + .PHONY: build build: - go build + $(GO) build .PHONY: fmt fmt: - go fmt ./... \ No newline at end of file + $(GO) fmt ./... + +.PHONY: vet +vet: build + $(GO) vet ./... + $(GO) vet -vettool=gitea-vet ./... + +.PHONY: lint +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 $(shell $(GO) env GOPATH)/bin v1.24.0; \ + fi + golangci-lint run --timeout 5m \ No newline at end of file diff --git a/README.md b/README.md index 5fc03e0..d311c04 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # gitea-vet + +[![Build Status](https://drone.gitea.com/api/badges/jolheiser/gitea-vet/status.svg)](https://drone.gitea.com/jolheiser/gitea-vet) + `go vet` tool for Gitea | Analyzer | Description | diff --git a/checks/imports.go b/checks/imports.go index 6ef5975..9716e5f 100644 --- a/checks/imports.go +++ b/checks/imports.go @@ -22,11 +22,12 @@ func runImports(pass *analysis.Pass) (interface{}, error) { for _, im := range file.Imports { var lvl int val := im.Path.Value - if importHasPrefix(val, "code.gitea.io") { + switch { + case importHasPrefix(val, "code.gitea.io"): lvl = 2 - } else if strings.Contains(val, ".") { + case strings.Contains(val, "."): lvl = 3 - } else { + default: lvl = 1 } @@ -43,12 +44,3 @@ func runImports(pass *analysis.Pass) (interface{}, error) { func importHasPrefix(s, p string) bool { return strings.HasPrefix(s, "\""+p) } - -func sliceHasPrefix(s string, prefixes ...string) bool { - for _, p := range prefixes { - if importHasPrefix(s, p) { - return true - } - } - return false -} diff --git a/main.go b/main.go index 9b8b000..4a77e64 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ package main import ( "gitea.com/jolheiser/gitea-vet/checks" + "golang.org/x/tools/go/analysis/unitchecker" )