Skip to content

Commit 35a2909

Browse files
author
Ronen Hilewicz
committed
Update linter
1 parent ae26f87 commit 35a2909

8 files changed

Lines changed: 108 additions & 193 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
env:
1818
PRE_RELEASE: ${{ github.ref == 'refs/heads/main' && 'development' || '' }}
1919
GO_VERSION: "1.23"
20-
GO_LANGCI_LINT_VERSION: "v1.61.0"
20+
GO_LANGCI_LINT_VERSION: v2.0.2
2121
GO_TESTSUM_VERSION: "1.11.0"
2222

2323
jobs:
@@ -33,7 +33,7 @@ jobs:
3333
go-version: ${{ env.GO_VERSION }}
3434
-
3535
name: Lint
36-
uses: golangci/golangci-lint-action@v6
36+
uses: golangci/golangci-lint-action@v7
3737
with:
3838
version: ${{ env.GO_LANGCI_LINT_VERSION }}
3939
verify: false # `golangci-lint config verify` checks against the latest schema instead of its own version.

.golangci.yaml

Lines changed: 45 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,52 @@
11
---
2-
# golangci.com configuration
3-
# https://github.com/golangci/golangci/wiki/Configuration
2+
# Configuration
3+
# https://golangci-lint.run/usage/configuration/
44

5-
linters-settings:
6-
funlen:
7-
lines: 100
8-
statements: 80
9-
goconst:
10-
min-len: 2
11-
min-occurrences: 2
12-
gocritic:
13-
enabled-tags:
14-
- diagnostic
15-
- experimental
16-
- opinionated
17-
- performance
18-
- style
19-
disabled-checks:
20-
- dupImport # https://github.com/go-critic/go-critic/issues/845
21-
- ifElseChain
22-
- octalLiteral
23-
- whyNoLint
24-
- wrapperFunc
25-
gocyclo:
26-
min-complexity: 18
27-
goimports:
28-
local-prefixes: github.com/golangci/golangci-lint
29-
mnd:
30-
checks:
31-
- argument
32-
- case
33-
- condition
34-
- return
35-
govet:
36-
shadow: true
37-
settings:
38-
printf:
39-
funcs:
40-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
41-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
42-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
43-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
44-
lll:
45-
line-length: 140
46-
misspell:
47-
locale: US
48-
nolintlint:
49-
allow-unused: false # report any unused nolint directives
50-
require-explanation: false # don't require an explanation for nolint directives
51-
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
5+
version: "2"
526

537
linters:
54-
# please, do not use `enable-all`: it's deprecated and will be removed soon.
55-
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
56-
disable-all: false
8+
# https://golangci-lint.run/usage/configuration/#linters-configuration
9+
default: all
10+
11+
# explicitly disabled linters
12+
disable:
13+
- depguard
14+
- exhaustruct
15+
- gochecknoglobals # no configuration options
16+
- nlreturn # redundant with wsl
17+
- paralleltest
18+
- revive
19+
- thelper
20+
- varnamelen
21+
- wrapcheck
22+
23+
settings:
24+
cyclop:
25+
max-complexity: 12
26+
27+
funlen:
28+
lines: 80
29+
statements: 60
30+
ignore-comments: true
31+
32+
ireturn:
33+
allow:
34+
- error
35+
- generic
36+
37+
lll:
38+
line-length: 150
39+
40+
tagliatelle:
41+
case:
42+
rules:
43+
json: snake
44+
yaml: snake
45+
46+
formatters:
5747
enable:
58-
- asasalint
59-
- asciicheck
60-
- bidichk
61-
- bodyclose
62-
- canonicalheader
63-
- containedctx
64-
- contextcheck
65-
- copyloopvar
66-
- cyclop
67-
- decorder
68-
- dogsled
69-
- dupword
70-
- durationcheck
71-
- err113
72-
- errchkjson
73-
- errname
74-
- errorlint
75-
- exhaustive
76-
- fatcontext
77-
- forcetypeassert
78-
- funlen
79-
- gocheckcompilerdirectives
80-
- gochecknoinits
81-
- gochecknoglobals
82-
- gochecknoinits
83-
- gocognit
84-
- goconst
85-
- gocritic
86-
- gocyclo
87-
- godot
8848
- gofmt
49+
- gofumpt
8950
- goimports
90-
- goprintffuncname
91-
- gosec
92-
- gosmopolitan
93-
- grouper
94-
- importas
95-
- inamedparam
96-
- interfacebloat
97-
- intrange
98-
- lll
99-
- makezero
100-
- mirror
101-
- misspell
102-
- mnd
103-
- musttag
104-
- nakedret
105-
- nestif
106-
- nilerr
107-
- nilnil
108-
- noctx
109-
- nolintlint
110-
- nonamedreturns
111-
- perfsprint
112-
- prealloc
113-
- predeclared
114-
- reassign
115-
- rowserrcheck
116-
- stylecheck
117-
- testpackage
118-
- unconvert
119-
- unparam
120-
- usestdlibvars
121-
- wastedassign
122-
- whitespace
123-
- zerologlint
124-
125-
# don't enable:
126-
# - depguard
127-
# - dupl
128-
# - exhaustruct
129-
# - gci
130-
# - ginkgolinter
131-
# - gochecknoglobals
132-
# - gocognit
133-
# - godox
134-
# - gofumpt
135-
# - gomoddirectives
136-
# - ireturn
137-
# - lll
138-
# - nlreturn
139-
# - nolintlint # conflict with 1.19 gofmt changes
140-
# - protogetter
141-
# - prealloc
142-
# - revive
143-
# - wsl
144-
# - wrapcheck
145-
146-
issues:
147-
exclude-rules:
148-
- text: "unnamedResult:"
149-
linters:
150-
- gocritic
51+
disable:
52+
- gci # use gofumpt

custom_error_handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func CustomErrorHandler(
3434
continue
3535
}
3636

37-
value, hasErrorMetadata := errInfo.Metadata[HTTPStatusErrorMetadata]
37+
value, hasErrorMetadata := errInfo.GetMetadata()[HTTPStatusErrorMetadata]
3838
if !hasErrorMetadata {
3939
continue
4040
}
@@ -48,6 +48,7 @@ func CustomErrorHandler(
4848
httpStatusError.Err = err
4949
httpStatusError.HTTPStatus = code
5050
runtime.DefaultHTTPErrorHandler(ctx, gtw, runtimeMarshaler, httpResponseWriter, httpRequest, &httpStatusError)
51+
5152
return
5253
}
5354
}

errors.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
func NewAsertoError(code string, statusCode codes.Code, httpCode int, msg string) *AsertoError {
3131
asertoError := &AsertoError{code, statusCode, msg, httpCode, map[string]string{}, nil}
3232
asertoErrors[code] = asertoError
33+
3334
return asertoError
3435
}
3536

@@ -88,19 +89,23 @@ func (e *AsertoError) Error() string {
8889
}
8990

9091
innerMessage := errsMessage
92+
9193
if len(e.data) > 0 {
9294
for k, v := range e.data {
9395
if k == "msg" {
9496
if innerMessage != "" {
9597
innerMessage = colon + innerMessage
9698
}
99+
97100
innerMessage = v + innerMessage
98101
}
99102
}
100103
}
104+
101105
if innerMessage == "" {
102106
return fmt.Sprintf("%s %s", e.Code, e.Message)
103107
}
108+
104109
return fmt.Sprintf("%s %s: %s", e.Code, e.Message, innerMessage)
105110
}
106111

@@ -150,30 +155,35 @@ func (e *AsertoError) Msgf(message string, args ...interface{}) *AsertoError {
150155
} else {
151156
c.data[MessageKey] = message
152157
}
158+
153159
return c
154160
}
155161

156162
func (e *AsertoError) Str(key, value string) *AsertoError {
157163
c := e.Copy()
158164
c.data[key] = value
165+
159166
return c
160167
}
161168

162169
func (e *AsertoError) Int(key string, value int) *AsertoError {
163170
c := e.Copy()
164171
c.data[key] = strconv.Itoa(value)
172+
165173
return c
166174
}
167175

168176
func (e *AsertoError) Int32(key string, value int32) *AsertoError {
169177
c := e.Copy()
170178
c.data[key] = strconv.FormatInt(int64(value), 10)
179+
171180
return c
172181
}
173182

174183
func (e *AsertoError) Int64(key string, value int64) *AsertoError {
175184
c := e.Copy()
176185
c.data[key] = strconv.FormatInt(value, 10)
186+
177187
return c
178188
}
179189

@@ -187,19 +197,21 @@ func (e *AsertoError) Bool(key string, value bool) *AsertoError {
187197
func (e *AsertoError) Duration(key string, value time.Duration) *AsertoError {
188198
c := e.Copy()
189199
c.data[key] = value.String()
200+
190201
return c
191202
}
192203

193204
func (e *AsertoError) Time(key string, value time.Time) *AsertoError {
194205
c := e.Copy()
195206
c.data[key] = value.UTC().Format(time.RFC3339)
207+
196208
return c
197209
}
198210

199211
func (e *AsertoError) FromReader(key string, value io.Reader) *AsertoError {
200212
buf := &strings.Builder{}
201-
_, err := io.Copy(buf, value)
202-
if err != nil {
213+
214+
if _, err := io.Copy(buf, value); err != nil {
203215
return e.Err(err)
204216
}
205217

@@ -212,6 +224,7 @@ func (e *AsertoError) FromReader(key string, value io.Reader) *AsertoError {
212224
func (e *AsertoError) Interface(key string, value interface{}) *AsertoError {
213225
c := e.Copy()
214226
c.data[key] = fmt.Sprintf("%+v", value)
227+
215228
return c
216229
}
217230

@@ -242,6 +255,7 @@ func (e *AsertoError) MarshalZerologObject(event *zerolog.Event) {
242255

243256
func (e *AsertoError) GRPCStatus() *status.Status {
244257
errResult := status.New(e.StatusCode, e.Message)
258+
245259
errResult, err := errResult.WithDetails(&errdetails.ErrorInfo{
246260
Metadata: e.Data(),
247261
Domain: e.Code,
@@ -256,12 +270,14 @@ func (e *AsertoError) GRPCStatus() *status.Status {
256270
func (e *AsertoError) WithGRPCStatus(grpcCode codes.Code) *AsertoError {
257271
c := e.Copy()
258272
c.StatusCode = grpcCode
273+
259274
return c
260275
}
261276

262277
func (e *AsertoError) WithHTTPStatus(httpStatus int) *AsertoError {
263278
c := e.Copy()
264279
c.HTTPCode = httpStatus
280+
265281
return c
266282
}
267283

@@ -280,12 +296,14 @@ func FromGRPCStatus(grpcStatus status.Status) *AsertoError {
280296

281297
for _, detail := range grpcStatus.Details() {
282298
if t, ok := detail.(*errdetails.ErrorInfo); ok {
283-
result = asertoErrors[t.Domain]
299+
result = asertoErrors[t.GetDomain()]
284300
if result == nil {
285301
return nil
286302
}
287-
result.data = t.Metadata
303+
304+
result.data = t.GetMetadata()
288305
}
306+
289307
if result != nil {
290308
break
291309
}
@@ -298,8 +316,10 @@ func FromGRPCStatus(grpcStatus status.Status) *AsertoError {
298316
* Retrieves the most inner logger associated with an error.
299317
*/
300318
func Logger(err error) *zerolog.Logger {
301-
var logger *zerolog.Logger
302-
var ce *ContextError
319+
var (
320+
logger *zerolog.Logger
321+
ce *ContextError
322+
)
303323

304324
if err == nil {
305325
return logger
@@ -384,6 +404,7 @@ func extractLogger(ctx context.Context) *zerolog.Logger {
384404
if ctx == nil {
385405
return nil
386406
}
407+
387408
logger := zerolog.Ctx(ctx)
388409
if logger == zerolog.DefaultContextLogger || logger.GetLevel() == zerolog.Disabled {
389410
logger = nil

0 commit comments

Comments
 (0)