Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate linters with golangci-lint #3758

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: golangci-lint
on:
push:
permissions:
contents: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.19
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.50.1
args: --verbose --timeout 10m --fix=false
22 changes: 22 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://golangci-lint.run/usage/configuration/#config-file
linters:
disable-all: true
enable:
- errcheck
- goimports
- revive # revive supersedes golint, which is now archived
- staticcheck
- vet
run:
skip-dirs:
- ^api
- ^proto
- ^.git
issues:
# Show only new issues: if there are unstaged changes or untracked files,
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
# It's a super-useful option for integration of golangci-lint into existing large codebase.
# It's not practical to fix all existing issues at the moment of integration:
# much better don't allow issues in new code.
new-from-rev: HEAD~
fix: true
29 changes: 4 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ INTEG_TEST_COVERPKG := -coverpkg="$(MODULE_ROOT)/client/...,$(MODULE_ROOT)/commo
##### Tools #####
update-checkers:
@printf $(COLOR) "Install/update check tools..."
@go install golang.org/x/lint/golint@latest
@go install golang.org/x/tools/cmd/goimports@latest
@go install honnef.co/go/tools/cmd/staticcheck@v0.3.2
@go install github.com/kisielk/errcheck@v1.6.1
@go install github.com/googleapis/api-linter/cmd/api-linter@v1.32.3
@go install github.com/bufbuild/buf/cmd/buf@v1.6.0
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1


update-mockgen:
@printf $(COLOR) "Install/update mockgen tool..."
Expand Down Expand Up @@ -222,27 +221,7 @@ copyright:

lint:
@printf $(COLOR) "Run linter..."
@golint ./...

vet:
@printf $(COLOR) "Run go vet..."
@go vet ./... || true

goimports-check:
@printf $(COLOR) "Run goimports checks..."
@GO_IMPORTS_OUTPUT=$$(goimports -l .); if [ -n "$${GO_IMPORTS_OUTPUT}" ]; then echo "$${GO_IMPORTS_OUTPUT}" && echo "Please run 'make goimports'" && exit 1; fi

goimports:
@printf $(COLOR) "Run goimports..."
@goimports -w .

staticcheck:
@printf $(COLOR) "Run staticcheck..."
@staticcheck ./...

errcheck:
@printf $(COLOR) "Run errcheck..."
@errcheck ./... || true
@golangci-lint run

api-linter:
@printf $(COLOR) "Run api-linter..."
Expand All @@ -264,7 +243,7 @@ shell-check:
@printf $(COLOR) "Run shellcheck for script files..."
@shellcheck $(ALL_SCRIPTS)

check: copyright-check goimports-check lint vet staticcheck errcheck
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove check.

check: copyright-check

##### Tests #####
clean-test-results:
Expand Down