Skip to content

Commit 21e34ec

Browse files
authored
lint: upgrade golangci-lint configuration (#1275)
golangci-lint now has a v2 configuration format that includes specifying formatters as well. Migrate the configuration with `golangci-lint migrate` and manually copy the comments over. Also take advantage of the `-diff` flag of `go mod tidy` instead of `git diff` after the fact.
1 parent b002d43 commit 21e34ec

5 files changed

Lines changed: 70 additions & 75 deletions

File tree

.github/workflows/go.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ jobs:
6969
uses: actions/setup-go@v5
7070
with:
7171
go-version: 1.25.x
72-
cache: false # managed by golangci-lint
7372

74-
- uses: golangci/golangci-lint-action@v6
73+
- uses: golangci/golangci-lint-action@v8
7574
name: Install golangci-lint
7675
with:
7776
version: latest

.golangci.yml

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,93 @@
1-
output:
2-
# Make output more digestible with quickfix in vim/emacs/etc.
3-
sort-results: true
4-
print-issued-lines: false
1+
version: "2"
2+
3+
issues:
4+
# Print all issues reported by all linters.
5+
max-issues-per-linter: 0
6+
max-same-issues: 0
57

68
linters:
79
# We'll track the golangci-lint default linters manually
810
# instead of letting them change without our control.
9-
disable-all: true
11+
default: none
1012
enable:
1113
# golangci-lint defaults:
12-
- gosimple
1314
- govet
1415
- ineffassign
1516
- staticcheck
1617
- unused
1718

1819
# Our own extras:
19-
- gofumpt
20-
- nolintlint # lints nolint directives
21-
- revive
2220
- errorlint
21+
- nolintlint # lints //nolint directives
22+
- revive
2323

2424
# License header check:
2525
- goheader
2626

27-
linters-settings:
28-
govet:
29-
# These govet checks are disabled by default, but they're useful.
30-
enable:
31-
- nilness
32-
- reflectvaluecompare
33-
- sortslice
34-
- unusedwrite
35-
36-
goheader:
37-
values:
38-
const:
39-
COMPANY: 'Uber Technologies, Inc.'
40-
regexp:
41-
YEAR_RANGE: '\d{4}(-\d{4})?'
42-
template: |-
43-
Copyright (c) {{ YEAR_RANGE }} {{ COMPANY }}
27+
settings:
4428

45-
Permission is hereby granted, free of charge, to any person obtaining a copy
46-
of this software and associated documentation files (the "Software"), to deal
47-
in the Software without restriction, including without limitation the rights
48-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49-
copies of the Software, and to permit persons to whom the Software is
50-
furnished to do so, subject to the following conditions:
29+
# These govet checks are disabled by default, but they're useful.
30+
govet:
31+
enable:
32+
- nilness
33+
- reflectvaluecompare
34+
- sortslice
35+
- unusedwrite
5136

52-
The above copyright notice and this permission notice shall be included in
53-
all copies or substantial portions of the Software.
37+
goheader:
38+
values:
39+
const:
40+
COMPANY: Uber Technologies, Inc.
41+
regexp:
42+
YEAR_RANGE: \d{4}(-\d{4})?
43+
template: |-
44+
Copyright (c) {{ YEAR_RANGE }} {{ COMPANY }}
5445
55-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
61-
THE SOFTWARE.
46+
Permission is hereby granted, free of charge, to any person obtaining a copy
47+
of this software and associated documentation files (the "Software"), to deal
48+
in the Software without restriction, including without limitation the rights
49+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50+
copies of the Software, and to permit persons to whom the Software is
51+
furnished to do so, subject to the following conditions:
6252
53+
The above copyright notice and this permission notice shall be included in
54+
all copies or substantial portions of the Software.
6355
64-
issues:
65-
# Print all issues reported by all linters.
66-
max-issues-per-linter: 0
67-
max-same-issues: 0
56+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
62+
THE SOFTWARE.
6863
69-
# Don't ignore some of the issues that golangci-lint considers okay.
70-
# This includes documenting all exported entities.
71-
exclude-use-default: false
64+
exclusions:
65+
generated: lax
66+
rules:
67+
# Don't warn on unused parameters.
68+
# Parameter names are useful; replacing them with '_' is undesirable.
69+
- linters: [revive]
70+
text: 'unused-parameter: parameter \S+ seems to be unused, consider removing or renaming it as _'
7271

73-
exclude-rules:
74-
# Don't warn on unused parameters.
75-
# Parameter names are useful; replacing them with '_' is undesirable.
76-
- linters: [revive]
77-
text: 'unused-parameter: parameter \S+ seems to be unused, consider removing or renaming it as _'
72+
# staticcheck already has smarter checks for empty blocks.
73+
# revive's empty-block linter has false positives.
74+
# For example, as of writing this, the following is not allowed.
75+
# for foo() { }
76+
- linters: [revive]
77+
text: 'empty-block: this block is empty, you can remove it'
7878

79-
# staticcheck already has smarter checks for empty blocks.
80-
# revive's empty-block linter has false positives.
81-
# For example, as of writing this, the following is not allowed.
82-
# for foo() { }
83-
- linters: [revive]
84-
text: 'empty-block: this block is empty, you can remove it'
79+
# It's okay if internal packages and examples in docs/
80+
# don't have package comments.
81+
- linters: [revive]
82+
path: .+/internal/.+|^internal/.+|^docs/.+
83+
text: should have a package comment
8584

86-
# It's okay if internal packages and examples in docs/
87-
# don't have package comments.
88-
- linters: [revive]
89-
path: '.+/internal/.+|^internal/.+|^docs/.+'
90-
text: 'should have a package comment'
85+
# It's okay for tests to use dot imports.
86+
- linters: [revive]
87+
path: _test\.go$
88+
text: should not use dot imports
9189

92-
# It's okay for tests to use dot imports.
93-
- linters: [revive]
94-
path: '_test\.go$'
95-
text: 'should not use dot imports'
90+
formatters:
91+
enable: [gofumpt]
92+
exclusions:
93+
generated: lax

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ tidy-lint:
5454
@$(foreach mod,$(MODULES), \
5555
(cd $(mod) && \
5656
echo "[lint] tidy: $(mod)" && \
57-
go mod tidy && \
58-
git diff --exit-code -- go.mod go.sum) &&) true
57+
go mod tidy -diff) &&) true
5958

6059
.PHONY: fx-lint
6160
fx-lint: $(FXLINT)

annotated_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,7 @@ func TestAnnotate(t *testing.T) {
13421342

13431343
app := NewForTest(t,
13441344
fx.Provide(
1345-
//lint:ignore ST1008 we want to test error in the middle.
1346-
fx.Annotate(func() (*a, error, *a) {
1345+
fx.Annotate(func() (*a, error, *a) { //nolint:staticcheck // we want to test error in the middle.
13471346
return &a{}, nil, &a{}
13481347
}, fx.ResultTags(`name:"firstA"`, ``, `name:"secondA"`)),
13491348
),

extract_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestExtract(t *testing.T) {
185185
defer app.RequireStart().RequireStop()
186186

187187
// Unexported fields are left unchanged.
188-
assert.NotEqual(t, "foo", out.type4.foo)
188+
assert.NotEqual(t, "foo", out.foo)
189189
})
190190

191191
t.Run("DuplicateFields", func(t *testing.T) {

0 commit comments

Comments
 (0)