Skip to content

Commit 2d30434

Browse files
authored
Update linter to 1.55.1 and fix linter errors (dapr#71)
* Update linter to 1.55.1 and fix linter errors Signed-off-by: ItalyPaleAle <[email protected]> * Also disable tagalign linter Signed-off-by: ItalyPaleAle <[email protected]> --------- Signed-off-by: ItalyPaleAle <[email protected]>
1 parent a0df11f commit 2d30434

31 files changed

+238
-219
lines changed

.github/workflows/kit.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ jobs:
2121
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries
2222
runs-on: ${{ matrix.os }}
2323
env:
24-
GOVER: "1.20"
2524
GOOS: ${{ matrix.target_os }}
2625
GOARCH: ${{ matrix.target_arch }}
2726
GOPROXY: https://proxy.golang.org
28-
GOLANGCI_LINT_VER: v1.51.2
27+
GOLANGCI_LINT_VER: v1.55.1
2928
strategy:
3029
matrix:
3130
os: [ubuntu-latest, windows-latest, macOS-latest]
@@ -43,15 +42,15 @@ jobs:
4342
- os: macOS-latest
4443
target_arch: arm
4544
steps:
46-
- name: Set up Go ${{ env.GOVER }}
47-
uses: actions/setup-go@v1
48-
with:
49-
go-version: ${{ env.GOVER }}
5045
- name: Check out code into the Go module directory
51-
uses: actions/checkout@v2
46+
uses: actions/checkout@v4
47+
- name: Set up Go
48+
uses: actions/setup-go@v4
49+
with:
50+
go-version-file: 'go.mod'
5251
- name: Run golangci-lint
5352
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
54-
uses: golangci/golangci-lint-action@v3.2.0
53+
uses: golangci/golangci-lint-action@v3
5554
with:
5655
version: ${{ env.GOLANGCI_LINT_VER }}
5756
skip-cache: true
@@ -65,4 +64,4 @@ jobs:
6564
run: make test
6665
- name: Codecov
6766
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
68-
uses: codecov/codecov-action@v1
67+
uses: codecov/codecov-action@v3

.golangci.yml

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,53 @@ linters-settings:
118118
# minimal occurrences count to trigger, 3 by default
119119
min-occurrences: 5
120120
depguard:
121-
list-type: denylist
122-
include-go-root: false
123-
packages-with-error-message:
124-
- "github.com/Sirupsen/logrus": "must use github.com/dapr/kit/logger"
125-
- "github.com/agrea/ptr": "must use github.com/dapr/kit/ptr"
126-
- "go.uber.org/atomic": "must use sync/atomic"
127-
- "golang.org/x/net/context": "must use context"
128-
- "github.com/pkg/errors": "must use standard library (errors package and/or fmt.Errorf)"
129-
- "github.com/go-chi/chi$": "must use github.com/go-chi/chi/v5"
130-
- "github.com/cenkalti/backoff$": "must use github.com/cenkalti/backoff/v4"
131-
- "github.com/cenkalti/backoff/v2": "must use github.com/cenkalti/backoff/v4"
132-
- "github.com/cenkalti/backoff/v3": "must use github.com/cenkalti/backoff/v4"
133-
- "github.com/benbjohnson/clock": "must use k8s.io/utils/clock"
134-
- "github.com/ghodss/yaml": "must use sigs.k8s.io/yaml"
135-
- "gopkg.in/yaml.v2": "must use gopkg.in/yaml.v3"
136-
- "github.com/golang-jwt/jwt": "must use github.com/lestrrat-go/jwx/v2"
137-
- "github.com/golang-jwt/jwt/v2": "must use github.com/lestrrat-go/jwx/v2"
138-
- "github.com/golang-jwt/jwt/v3": "must use github.com/lestrrat-go/jwx/v2"
139-
- "github.com/golang-jwt/jwt/v4": "must use github.com/lestrrat-go/jwx/v2"
140-
- "github.com/gogo/status": "must use google.golang.org/grpc/status"
141-
- "github.com/gogo/protobuf": "must use google.golang.org/protobuf"
142-
- "github.com/lestrrat-go/jwx/jwa": "must use github.com/lestrrat-go/jwx/v2"
143-
- "github.com/lestrrat-go/jwx/jwt": "must use github.com/lestrrat-go/jwx/v2"
144-
- "github.com/labstack/gommon/log": "must use github.com/dapr/kit/logger"
145-
- "github.com/gobuffalo/logger": "must use github.com/dapr/kit/logger"
121+
rules:
122+
main:
123+
deny:
124+
- pkg: "github.com/Sirupsen/logrus"
125+
desc: "must use github.com/dapr/kit/logger"
126+
- pkg: "github.com/agrea/ptr"
127+
desc: "must use github.com/dapr/kit/ptr"
128+
- pkg: "go.uber.org/atomic"
129+
desc: "must use sync/atomic"
130+
- pkg: "golang.org/x/net/context"
131+
desc: "must use context"
132+
- pkg: "github.com/pkg/errors"
133+
desc: "must use standard library (errors package and/or fmt.Errorf)"
134+
- pkg: "github.com/go-chi/chi$"
135+
desc: "must use github.com/go-chi/chi/v5"
136+
- pkg: "github.com/cenkalti/backoff$"
137+
desc: "must use github.com/cenkalti/backoff/v4"
138+
- pkg: "github.com/cenkalti/backoff/v2"
139+
desc: "must use github.com/cenkalti/backoff/v4"
140+
- pkg: "github.com/cenkalti/backoff/v3"
141+
desc: "must use github.com/cenkalti/backoff/v4"
142+
- pkg: "github.com/benbjohnson/clock"
143+
desc: "must use k8s.io/utils/clock"
144+
- pkg: "github.com/ghodss/yaml"
145+
desc: "must use sigs.k8s.io/yaml"
146+
- pkg: "gopkg.in/yaml.v2"
147+
desc: "must use gopkg.in/yaml.v3"
148+
- pkg: "github.com/golang-jwt/jwt"
149+
desc: "must use github.com/lestrrat-go/jwx/v2"
150+
- pkg: "github.com/golang-jwt/jwt/v2"
151+
desc: "must use github.com/lestrrat-go/jwx/v2"
152+
- pkg: "github.com/golang-jwt/jwt/v3"
153+
desc: "must use github.com/lestrrat-go/jwx/v2"
154+
- pkg: "github.com/golang-jwt/jwt/v4"
155+
desc: "must use github.com/lestrrat-go/jwx/v2"
156+
- pkg: "github.com/gogo/status"
157+
desc: "must use google.golang.org/grpc/status"
158+
- pkg: "github.com/gogo/protobuf"
159+
desc: "must use google.golang.org/protobuf"
160+
- pkg: "github.com/lestrrat-go/jwx/jwa"
161+
desc: "must use github.com/lestrrat-go/jwx/v2"
162+
- pkg: "github.com/lestrrat-go/jwx/jwt"
163+
desc: "must use github.com/lestrrat-go/jwx/v2"
164+
- pkg: "github.com/labstack/gommon/log"
165+
desc: "must use github.com/dapr/kit/logger"
166+
- pkg: "github.com/gobuffalo/logger"
167+
desc: "must use github.com/dapr/kit/logger"
146168
misspell:
147169
# Correct spellings using locale preferences for US or UK.
148170
# Default is to use a neutral variety of English.
@@ -156,12 +178,6 @@ linters-settings:
156178
line-length: 120
157179
# tab width in spaces. Default to 1.
158180
tab-width: 1
159-
unused:
160-
# treat code as a program (not a library) and report unused exported identifiers; default is false.
161-
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
162-
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
163-
# with golangci-lint call it on a directory with the changed file.
164-
check-exported: false
165181
unparam:
166182
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
167183
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
@@ -249,6 +265,7 @@ linters:
249265
- nonamedreturns
250266
- errcheck
251267
- funlen
268+
- goconst
252269
- gochecknoglobals
253270
- gochecknoinits
254271
- gocyclo
@@ -287,6 +304,7 @@ linters:
287304
- cyclop
288305
- varnamelen
289306
- gosec
307+
- tagalign
290308
- errorlint
291309
- forcetypeassert
292310
- ifshort

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ test-race:
7676
################################################################################
7777
.PHONY: lint
7878
lint:
79-
# Due to https://github.com/golangci/golangci-lint/issues/580, we need to add --fix for windows
8079
$(GOLANGCI_LINT) run --timeout=20m
8180

8281
################################################################################

config/decode_test.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2425

2526
"github.com/dapr/kit/config"
2627
"github.com/dapr/kit/ptr"
@@ -187,7 +188,7 @@ func TestDecode(t *testing.T) {
187188
t.Run(name, func(t *testing.T) {
188189
var actual testConfig
189190
err := config.Decode(tc, &actual)
190-
assert.NoError(t, err)
191+
require.NoError(t, err)
191192
assert.Equal(t, expected, actual)
192193
})
193194
}
@@ -231,61 +232,60 @@ func TestDecodeErrors(t *testing.T) {
231232
"string": 1234,
232233
"stringPtr": 1234,
233234
}, &actual)
234-
if assert.Error(t, err) {
235-
errMsg := err.Error()
236-
expectedNumErrors := 32
237-
expectedPrefix := " error(s) decoding:"
238-
assert.True(t, strings.HasPrefix(errMsg, fmt.Sprintf("%d%s", expectedNumErrors, expectedPrefix)), errMsg)
239-
prefixIndex := strings.Index(errMsg, expectedPrefix)
240-
if assert.True(t, prefixIndex != -1) {
241-
errMsg = errMsg[prefixIndex+len(expectedPrefix):]
242-
errMsg = strings.TrimSpace(errMsg)
243-
errors := strings.Split(errMsg, "\n")
244-
errorSet := make(map[string]struct{}, len(errors))
245-
for _, e := range errors {
246-
errorSet[e] = struct{}{}
247-
}
248-
expectedErrors := []string{
249-
"* error decoding 'int': invalid int \"-badval\"",
250-
"* error decoding 'intPtr': invalid int \"-badval\"",
251-
"* error decoding 'int16': invalid int16 \"-badval\"",
252-
"* error decoding 'int16Ptr': invalid int16 \"-badval\"",
253-
"* error decoding 'int32': invalid int32 \"-badval\"",
254-
"* error decoding 'int32Ptr': invalid int32 \"-badval\"",
255-
"* error decoding 'int64': invalid int64 \"-badval\"",
256-
"* error decoding 'int64Ptr': invalid int64 \"-badval\"",
257-
"* error decoding 'int8': invalid int8 \"-badval\"",
258-
"* error decoding 'int8Ptr': invalid int8 \"-badval\"",
259-
"* error decoding 'uint': invalid uint \"-9999\"",
260-
"* error decoding 'uintPtr': invalid uint \"-9999\"",
261-
"* error decoding 'uint64': invalid uint64 \"-1234\"",
262-
"* error decoding 'uint64Ptr': invalid uint64 \"-1234\"",
263-
"* error decoding 'uint32': invalid uint32 \"-5678\"",
264-
"* error decoding 'uint32Ptr': invalid uint32 \"-5678\"",
265-
"* error decoding 'uint16': invalid uint16 \"-9012\"",
266-
"* error decoding 'uint16Ptr': invalid uint16 \"-9012\"",
267-
"* error decoding 'byte': invalid uint8 \"-1\"",
268-
"* error decoding 'bytePtr': invalid uint8 \"-1\"",
269-
"* error decoding 'float32': invalid float32 \"badval.5\"",
270-
"* error decoding 'float32Ptr': invalid float32 \"badval.5\"",
271-
"* error decoding 'float64': invalid float64 \"badval.5\"",
272-
"* error decoding 'float64Ptr': invalid float64 \"badval.5\"",
273-
"* error decoding 'duration': invalid duration \"badval\"",
274-
"* error decoding 'durationPtr': invalid duration \"badval\"",
275-
"* error decoding 'time': invalid time \"badval\"",
276-
"* error decoding 'timePtr': invalid time \"badval\"",
277-
"* error decoding 'decoded': invalid Decoded \"badval\": strconv.Atoi: parsing \"badval\": invalid syntax",
278-
"* error decoding 'decodedPtr': invalid Decoded \"badval\": strconv.Atoi: parsing \"badval\": invalid syntax",
279-
"* error decoding 'bool': invalid bool \"badval\"",
280-
"* error decoding 'boolPtr': invalid bool \"badval\"",
281-
}
282-
for _, expectedError := range expectedErrors {
283-
assert.Contains(t, errors, expectedError)
284-
delete(errorSet, expectedError)
285-
}
286-
assert.Empty(t, errorSet)
287-
}
235+
require.Error(t, err)
236+
237+
errMsg := err.Error()
238+
expectedNumErrors := 32
239+
expectedPrefix := " error(s) decoding:"
240+
assert.True(t, strings.HasPrefix(errMsg, fmt.Sprintf("%d%s", expectedNumErrors, expectedPrefix)), errMsg)
241+
prefixIndex := strings.Index(errMsg, expectedPrefix)
242+
require.NotEqual(t, -1, prefixIndex)
243+
errMsg = errMsg[prefixIndex+len(expectedPrefix):]
244+
errMsg = strings.TrimSpace(errMsg)
245+
errors := strings.Split(errMsg, "\n")
246+
errorSet := make(map[string]struct{}, len(errors))
247+
for _, e := range errors {
248+
errorSet[e] = struct{}{}
249+
}
250+
expectedErrors := []string{
251+
"* error decoding 'int': invalid int \"-badval\"",
252+
"* error decoding 'intPtr': invalid int \"-badval\"",
253+
"* error decoding 'int16': invalid int16 \"-badval\"",
254+
"* error decoding 'int16Ptr': invalid int16 \"-badval\"",
255+
"* error decoding 'int32': invalid int32 \"-badval\"",
256+
"* error decoding 'int32Ptr': invalid int32 \"-badval\"",
257+
"* error decoding 'int64': invalid int64 \"-badval\"",
258+
"* error decoding 'int64Ptr': invalid int64 \"-badval\"",
259+
"* error decoding 'int8': invalid int8 \"-badval\"",
260+
"* error decoding 'int8Ptr': invalid int8 \"-badval\"",
261+
"* error decoding 'uint': invalid uint \"-9999\"",
262+
"* error decoding 'uintPtr': invalid uint \"-9999\"",
263+
"* error decoding 'uint64': invalid uint64 \"-1234\"",
264+
"* error decoding 'uint64Ptr': invalid uint64 \"-1234\"",
265+
"* error decoding 'uint32': invalid uint32 \"-5678\"",
266+
"* error decoding 'uint32Ptr': invalid uint32 \"-5678\"",
267+
"* error decoding 'uint16': invalid uint16 \"-9012\"",
268+
"* error decoding 'uint16Ptr': invalid uint16 \"-9012\"",
269+
"* error decoding 'byte': invalid uint8 \"-1\"",
270+
"* error decoding 'bytePtr': invalid uint8 \"-1\"",
271+
"* error decoding 'float32': invalid float32 \"badval.5\"",
272+
"* error decoding 'float32Ptr': invalid float32 \"badval.5\"",
273+
"* error decoding 'float64': invalid float64 \"badval.5\"",
274+
"* error decoding 'float64Ptr': invalid float64 \"badval.5\"",
275+
"* error decoding 'duration': invalid duration \"badval\"",
276+
"* error decoding 'durationPtr': invalid duration \"badval\"",
277+
"* error decoding 'time': invalid time \"badval\"",
278+
"* error decoding 'timePtr': invalid time \"badval\"",
279+
"* error decoding 'decoded': invalid Decoded \"badval\": strconv.Atoi: parsing \"badval\": invalid syntax",
280+
"* error decoding 'decodedPtr': invalid Decoded \"badval\": strconv.Atoi: parsing \"badval\": invalid syntax",
281+
"* error decoding 'bool': invalid bool \"badval\"",
282+
"* error decoding 'boolPtr': invalid bool \"badval\"",
283+
}
284+
for _, expectedError := range expectedErrors {
285+
assert.Contains(t, errors, expectedError)
286+
delete(errorSet, expectedError)
288287
}
288+
assert.Empty(t, errorSet)
289289
}
290290

291291
func getTimeVal() time.Time {

config/normalize_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestNormalize(t *testing.T) {
9696
actual, err := config.Normalize(tc.input)
9797
if tc.err != "" {
9898
require.Error(t, err)
99-
assert.EqualError(t, err, tc.err)
99+
require.EqualError(t, err, tc.err)
100100
} else {
101101
require.NoError(t, err)
102102
}

config/prefix_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"testing"
1818

1919
"github.com/stretchr/testify/assert"
20+
"github.com/stretchr/testify/require"
2021

2122
"github.com/dapr/kit/config"
2223
)
@@ -60,9 +61,8 @@ func TestPrefixedBy(t *testing.T) {
6061
t.Run(name, func(t *testing.T) {
6162
actual, err := config.PrefixedBy(tc.input, tc.prefix)
6263
if tc.err != "" {
63-
if assert.Error(t, err) {
64-
assert.Equal(t, tc.err, err.Error())
65-
}
64+
require.Error(t, err)
65+
assert.Equal(t, tc.err, err.Error())
6666
} else {
6767
assert.Equal(t, tc.expected, actual, "unexpected output")
6868
}

cron/chain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestChainDelayIfStillRunning(t *testing.T) {
170170
assert.EventuallyWithT(t, func(c *assert.CollectT) {
171171
started, done = j.Started(), j.Done()
172172
if started != 2 || done != 2 {
173-
c.Errorf("expected both jobs done, got %v %v", started, done)
173+
c.Errorf("expected both jobs done, got %v %v", started, done) //nolint:testifylint
174174
}
175175
}, 100*time.Millisecond, 10*time.Millisecond)
176176
})

cron/cron.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Job interface {
5959
type Schedule interface {
6060
// Next returns the next activation time, later than the given time.
6161
// Next is invoked initially, and then each time the job is run.
62-
Next(time.Time) time.Time
62+
Next(t time.Time) time.Time
6363
}
6464

6565
// EntryID identifies an entry within a Cron instance
@@ -140,7 +140,7 @@ func New(opts ...Option) *Cron {
140140
running: false,
141141
runningMu: sync.Mutex{},
142142
logger: DefaultLogger,
143-
location: time.Local,
143+
location: time.Local, //nolint:gosmopolitan
144144
parser: standardParser,
145145
clk: clock.RealClock{},
146146
}

cron/cron_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func TestRemoveWhileRunning(t *testing.T) {
228228
defer cron.Stop()
229229

230230
id, err := cron.AddFunc("* * * * * ?", func() { wg.Done() })
231-
assert.NoError(t, err)
231+
require.NoError(t, err)
232232
assert.Eventually(t, clock.HasWaiters, OneSecond, 10*time.Millisecond)
233233

234234
cron.Remove(id)

cron/option_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestWithVerboseLogger(t *testing.T) {
5959
out := buf.String()
6060
if !strings.Contains(out, "schedule,") ||
6161
!strings.Contains(out, "run,") {
62-
c.Errorf("expected to see some actions, got: %v", out)
62+
c.Errorf("expected to see some actions, got: %v", out) //nolint:testifylint
6363
}
6464
}, time.Second, time.Millisecond*10)
6565
}

0 commit comments

Comments
 (0)