Skip to content

Commit 6c9a8c2

Browse files
authored
Upgrade to golangci-lint to 1.54.2 and updates depguard config interface (#443)
* bump golangci version Signed-off-by: mikeee <[email protected]> * refactor depguard config Signed-off-by: mikeee <[email protected]> * exclude unused options Signed-off-by: mikeee <[email protected]> * remove locale option Signed-off-by: mikeee <[email protected]> * reassign iterated variables inside the loops Signed-off-by: mikeee <[email protected]> --------- Signed-off-by: mikeee <[email protected]>
1 parent 710492a commit 6c9a8c2

File tree

4 files changed

+58
-50
lines changed

4 files changed

+58
-50
lines changed

.github/workflows/test-on-push.yaml

+32-34
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
- main
88

99
jobs:
10-
1110
build:
1211
name: Test on ${{ matrix.gover }}
1312
runs-on: ubuntu-latest
@@ -19,38 +18,37 @@ jobs:
1918
- "1.20"
2019
env:
2120
GOVER: ${{ matrix.gover }}
22-
GOLANGCILINT_VER: v1.52.2
21+
GOLANGCILINT_VER: v1.54.2
2322

2423
steps:
25-
26-
- name: Setup
27-
uses: actions/setup-go@v3
28-
with:
29-
go-version: ${{ env.GOVER }}
30-
31-
- name: Checkout
32-
uses: actions/checkout@v3
33-
34-
- name: Cache
35-
uses: actions/cache@v3
36-
with:
37-
path: ~/go/pkg/mod
38-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
39-
restore-keys: |
40-
${{ runner.os }}-go-
41-
42-
- name: Tidy
43-
run: make tidy
44-
45-
- name: Test
46-
run: make test
47-
48-
- name: Cover
49-
uses: codecov/codecov-action@v3
50-
51-
- name: Lint
52-
uses: golangci/[email protected]
53-
with:
54-
version: ${{ env.GOLANGCILINT_VER }}
55-
skip-cache: true
56-
args: --timeout=10m0s
24+
- name: Setup
25+
uses: actions/setup-go@v3
26+
with:
27+
go-version: ${{ env.GOVER }}
28+
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
32+
- name: Cache
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/go/pkg/mod
36+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
${{ runner.os }}-go-
39+
40+
- name: Tidy
41+
run: make tidy
42+
43+
- name: Test
44+
run: make test
45+
46+
- name: Cover
47+
uses: codecov/codecov-action@v3
48+
49+
- name: Lint
50+
uses: golangci/[email protected]
51+
with:
52+
version: ${{ env.GOLANGCILINT_VER }}
53+
skip-cache: true
54+
args: --timeout=10m0s

.golangci.yml

+23-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ run:
3030
# won't be reported. Default value is empty list, but there is
3131
# no need to include all autogenerated files, we confidently recognize
3232
# autogenerated files. If it's not please let us know.
33-
skip-files:
33+
# skip-files:
3434
# - ".*\\.my\\.go$"
3535
# - lib/bad.go
3636

@@ -64,7 +64,7 @@ linters-settings:
6464

6565
# path to a file containing a list of functions to exclude from checking
6666
# see https://github.com/kisielk/errcheck#excluding-functions for details
67-
exclude:
67+
# exclude:
6868

6969
funlen:
7070
lines: 60
@@ -133,21 +133,29 @@ linters-settings:
133133
# minimal occurrences count to trigger, 3 by default
134134
min-occurrences: 5
135135
depguard:
136-
list-type: denylist
137-
include-go-root: false
138-
packages-with-error-message:
139-
- "github.com/Sirupsen/logrus": "must use github.com/dapr/kit/logger"
140-
- "github.com/agrea/ptr": "must use github.com/dapr/kit/ptr"
141-
- "go.uber.org/atomic": "must use sync/atomic"
142-
- "github.com/pkg/errors": "must use standard library (errors package and/or fmt.Errorf)"
143-
- "github.com/cenkalti/backoff": "must use github.com/cenkalti/backoff/v4"
144-
- "github.com/cenkalti/backoff/v2": "must use github.com/cenkalti/backoff/v4"
145-
- "github.com/cenkalti/backoff/v3": "must use github.com/cenkalti/backoff/v4"
136+
rules:
137+
main:
138+
deny:
139+
- pkg: "github.com/Sirupsen/logrus"
140+
desc: "you must use github.com/dapr/kit/logger"
141+
- pkg: "github.com/agrea/ptr"
142+
desc: "you must use github.com/dapr/kit/ptr"
143+
- pkg: "go.uber.org/atomic"
144+
desc: "you must use sync/atomic"
145+
- pkg: "github.com/pkg/errors"
146+
desc: "you must use the standard library (errors package and/or fmt.Errorf)"
147+
- pkg: "github.com/cenkalti/backoff"
148+
desc: "you must use github.com/cenkalti/backoff/v4"
149+
- pkg: "github.com/cenkalti/backoff/v2"
150+
desc: "you must use github.com/cenkalti/backoff/v4"
151+
- pkg: "github.com/cenkalti/backoff/v3"
152+
desc: "you must use github.com/cenkalti/backoff/v4"
146153
misspell:
147154
# Correct spellings using locale preferences for US or UK.
148-
# Default is to use a neutral variety of English.
155+
# Default is to use a neutral variety of English. (Do not specify a locale value)
149156
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
150-
locale: default
157+
# locale:
158+
151159
ignore-words:
152160
- someword
153161
lll:
@@ -185,7 +193,7 @@ linters-settings:
185193
# See https://go-critic.github.io/overview#checks-overview
186194
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
187195
# By default list of stable checks is used.
188-
enabled-checks:
196+
# enabled-checks:
189197

190198
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
191199
disabled-checks:

actor/state/actor_state_change_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func TestNewActorStateChange(t *testing.T) {
4646
},
4747
}
4848
for name, test := range tests {
49+
test := test
4950
t.Run(name, func(t *testing.T) {
5051
assert.Equal(t, test.want, NewActorStateChange(test.stateName, test.value, test.changeKind, &test.ttl))
5152
})

service/internal/topicregistrar_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ func TestTopicRegistrarValidation(t *testing.T) {
6161
},
6262
}
6363
for name, tt := range tests {
64+
tt := tt // dereference loop var
6465
t.Run(name, func(t *testing.T) {
6566
m := internal.TopicRegistrar{}
6667
if tt.err != "" {
67-
assert.EqualError(t, m.AddSubscription(&tt.sub, tt.fn), tt.err)
68+
assert.EqualError(t, m.AddSubscription(&tt.sub, tests[name].fn), tt.err)
6869
} else {
6970
assert.NoError(t, m.AddSubscription(&tt.sub, tt.fn))
7071
}

0 commit comments

Comments
 (0)