Skip to content

Commit 86e9d32

Browse files
Consolidate linters with golangci-lint (#3758)
1 parent 3a322bb commit 86e9d32

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

.github/workflows/golangci-lint.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
permissions:
5+
contents: read
6+
jobs:
7+
golangci:
8+
name: lint
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/setup-go@v2
12+
with:
13+
go-version: 1.19
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: golangci-lint
18+
uses: golangci/golangci-lint-action@v2
19+
with:
20+
version: v1.50.1
21+
args: --verbose --timeout 10m --fix=false

.golangci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# https://golangci-lint.run/usage/configuration/#config-file
2+
linters:
3+
disable-all: true
4+
enable:
5+
- errcheck
6+
- goimports
7+
- revive # revive supersedes golint, which is now archived
8+
- staticcheck
9+
- vet
10+
run:
11+
skip-dirs:
12+
- ^api
13+
- ^proto
14+
- ^.git
15+
issues:
16+
# Show only new issues: if there are unstaged changes or untracked files,
17+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
18+
# It's a super-useful option for integration of golangci-lint into existing large codebase.
19+
# It's not practical to fix all existing issues at the moment of integration:
20+
# much better don't allow issues in new code.
21+
new-from-rev: HEAD~
22+
fix: true

Makefile

+4-25
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ INTEG_TEST_COVERPKG := -coverpkg="$(MODULE_ROOT)/client/...,$(MODULE_ROOT)/commo
106106
##### Tools #####
107107
update-checkers:
108108
@printf $(COLOR) "Install/update check tools..."
109-
@go install golang.org/x/lint/golint@latest
110109
@go install golang.org/x/tools/cmd/goimports@latest
111-
@go install honnef.co/go/tools/cmd/staticcheck@v0.3.2
112-
@go install github.com/kisielk/errcheck@v1.6.1
113110
@go install github.com/googleapis/api-linter/cmd/api-linter@v1.32.3
114111
@go install github.com/bufbuild/buf/cmd/buf@v1.6.0
112+
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
113+
115114

116115
update-mockgen:
117116
@printf $(COLOR) "Install/update mockgen tool..."
@@ -222,27 +221,7 @@ copyright:
222221

223222
lint:
224223
@printf $(COLOR) "Run linter..."
225-
@golint ./...
226-
227-
vet:
228-
@printf $(COLOR) "Run go vet..."
229-
@go vet ./... || true
230-
231-
goimports-check:
232-
@printf $(COLOR) "Run goimports checks..."
233-
@GO_IMPORTS_OUTPUT=$$(goimports -l .); if [ -n "$${GO_IMPORTS_OUTPUT}" ]; then echo "$${GO_IMPORTS_OUTPUT}" && echo "Please run 'make goimports'" && exit 1; fi
234-
235-
goimports:
236-
@printf $(COLOR) "Run goimports..."
237-
@goimports -w .
238-
239-
staticcheck:
240-
@printf $(COLOR) "Run staticcheck..."
241-
@staticcheck ./...
242-
243-
errcheck:
244-
@printf $(COLOR) "Run errcheck..."
245-
@errcheck ./... || true
224+
@golangci-lint run
246225

247226
api-linter:
248227
@printf $(COLOR) "Run api-linter..."
@@ -264,7 +243,7 @@ shell-check:
264243
@printf $(COLOR) "Run shellcheck for script files..."
265244
@shellcheck $(ALL_SCRIPTS)
266245

267-
check: copyright-check goimports-check lint vet staticcheck errcheck
246+
check: copyright-check
268247

269248
##### Tests #####
270249
clean-test-results:

0 commit comments

Comments
 (0)