Lint: use golangci-lint

This commit is contained in:
loyalsoldier 2021-05-19 17:21:01 +08:00
parent 869b0b6f35
commit 7ebdc8ead7
No known key found for this signature in database
GPG Key ID: 23829BBC1ACF2C90
4 changed files with 55 additions and 29 deletions

38
.github/linters/.golangci.yml vendored Normal file
View File

@ -0,0 +1,38 @@
run:
timeout: 5m
skip-files:
- generated.*
issues:
new: true
linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- gci
- gocritic
- gofmt
- gofumpt
- goimports
- goprintffuncname
- gosimple
- govet
- ineffassign
- misspell
- nilerr
- nlreturn
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
- varcheck
- whitespace
disable:
- errcheck

View File

@ -1,32 +1,26 @@
name: golangci-lint name: golangci-lint
on: on:
push: push:
tags:
- v*
branches: branches:
- master - master
- main paths:
- "**/*.go"
- ".github/workflows/golangci-lint.yml"
pull_request: pull_request:
types: [opened, synchronize, reopened]
paths:
- "**/*.go"
- ".github/workflows/golangci-lint.yml"
jobs: jobs:
golangci: lint:
name: lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - name: Checkout codebase
uses: actions/checkout@v2
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: latest
version: v1.29 args: --config=.github/linters/.golangci.yml
# Optional: working directory, useful for monorepos
# working-directory: ./
# Optional: golangci-lint command line arguments.
args: --timeout=5m --print-issued-lines=true --print-linter-name=true --uniq-by-line=true
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true only-new-issues: true
# Optional: if set to true then the action will use pre-installed Go
# skip-go-installation: true

View File

@ -55,13 +55,7 @@ before_install:
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.string hello" - docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.string hello"
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.serialize.name test" - docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put current.serialize.name test"
- docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put sub.sub.key1 sub.sub.key" - docker exec etcd-gcr-v3.3.25 /bin/sh -c "ETCDCTL_API=3 /usr/local/bin/etcdctl put sub.sub.key1 sub.sub.key"
install:
- go get -u honnef.co/go/tools/cmd/staticcheck
- go get -u github.com/mdempsky/unconvert
- go get -u github.com/gordonklaus/ineffassign
before_script: before_script:
# -
- psql --version - psql --version
# - prepare for orm unit tests # - prepare for orm unit tests
- sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi" - sh -c "if [ '$ORM_DRIVER' = 'postgres' ]; then psql -c 'create database orm_test;' -U postgres; fi"
@ -77,9 +71,5 @@ after_success:
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)
script: script:
- GO111MODULE=on go test -coverprofile=coverage.txt -covermode=atomic ./... - GO111MODULE=on go test -coverprofile=coverage.txt -covermode=atomic ./...
- staticcheck -show-ignored -checks "-ST1017,-U1000,-ST1005,-S1034,-S1012,-SA4006,-SA6005,-SA1019,-SA1024" ./
- unconvert $(go list ./... | grep -v /vendor/)
- ineffassign .
- find . ! \( -path './vendor' -prune \) -type f -name '*.go' -print0 | xargs -0 gofmt -l -s
addons: addons:
postgresql: "9.6" postgresql: "9.6"

View File

@ -1,4 +1,6 @@
# developing # developing
- Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619)
- Chore: update dependencies. [4611](https://github.com/beego/beego/pull/4611) - Chore: update dependencies. [4611](https://github.com/beego/beego/pull/4611)
- Update orm_test.go/TestInsertOrUpdate with table-driven. [4609](https://github.com/beego/beego/pull/4609) - Update orm_test.go/TestInsertOrUpdate with table-driven. [4609](https://github.com/beego/beego/pull/4609)
- Add: Resp() method for web.Controller. [4588](https://github.com/beego/beego/pull/4588) - Add: Resp() method for web.Controller. [4588](https://github.com/beego/beego/pull/4588)
@ -41,7 +43,9 @@
- Optimize AddAutoPrefix: only register one router in case-insensitive mode. [4582](https://github.com/beego/beego/pull/4582) - Optimize AddAutoPrefix: only register one router in case-insensitive mode. [4582](https://github.com/beego/beego/pull/4582)
- Init exceptMethod by using reflection. [4583](https://github.com/beego/beego/pull/4583) - Init exceptMethod by using reflection. [4583](https://github.com/beego/beego/pull/4583)
- Deprecated BeeMap and replace all usage with `sync.map` [4616](https://github.com/beego/beego/pull/4616) - Deprecated BeeMap and replace all usage with `sync.map` [4616](https://github.com/beego/beego/pull/4616)
## Fix Sonar ## Fix Sonar
- [4608](https://github.com/beego/beego/pull/4608) - [4608](https://github.com/beego/beego/pull/4608)
- [4473](https://github.com/beego/beego/pull/4473) - [4473](https://github.com/beego/beego/pull/4473)
- [4474](https://github.com/beego/beego/pull/4474) - [4474](https://github.com/beego/beego/pull/4474)