diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..4932557bd --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,22 @@ +name: golangci-lint +on: + pull_request: +permissions: + contents: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.18 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + only-new-issues: true + args: --timeout 15m \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..a6fc1f043 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,58 @@ +un: + deadline: 15m + timeout: 15m + # didn't run linter on tests + tests: false + # don't check generated protobuf files + skip-dirs: + - pb/external_libs + - pkg/lib/pb + go: '1.18' + +linters-settings: + errcheck: + check-blank: true + errchkjson: + report-no-exported: true + gci: + sections: + - standard + - default + - prefix(github.com/anytypeio/go-anytype-middleware) + - blank + - dot + skip-generated: false + custom-order: true + goimports: + local-prefixes: github.com/anytypeio/go-anytype-middleware + govet: + check-shadowing: true + +linters: + disable-all: true + enable: + - dupl + - gci + - gocritic + - gofmt + - goimports + - gosec + - interfacebloat + - importas + - lll + - misspell + - nestif + - prealloc + - revive + - wsl + - unused + - errcheck + - funlen + - gosimple + - govet + - typecheck + - stylecheck + - unconvert + + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/Makefile b/Makefile index 321ff1893..8e7f88ebb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ export GOPRIVATE=github.com/anytypeio +export GOLANGCI_LINT_VERSION=v1.49.0 ifndef $(GOPATH) GOPATH=$(shell go env GOPATH) @@ -241,3 +242,20 @@ endif build-js: setup-go build-server protos-js @echo "Run 'make install-dev-js' instead if you want to build&install into ../js-anytype" + +install-linter: + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) + +run-linter: +ifdef GOLANGCI_LINT_BRANCH + @golangci-lint run -v ./... --new-from-rev=$(GOLANGCI_LINT_BRANCH) --timeout 15m +else + @golangci-lint run -v ./... --new-from-rev=master --timeout 15m +endif + +run-linter-fix: +ifdef GOLANGCI_LINT_BRANCH + @golangci-lint run -v ./... --new-from-rev=$(GOLANGCI_LINT_BRANCH) --timeout 15m --fix +else + @golangci-lint run -v ./... --new-from-rev=master --timeout 15m --fix +endif \ No newline at end of file