Skip to content

Commit 02b6a90

Browse files
authored
fix(clients): upgrade linter (#5476)
1 parent 77d149e commit 02b6a90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+323
-240
lines changed

.github/actions/setup/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ runs:
7878
if: ${{ inputs.language == 'go' }}
7979
shell: bash
8080
run: |
81-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
82-
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
81+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
8382
go install golang.org/x/tools/cmd/[email protected]
83+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
8484
8585
- name: Cache golangci-lint analysis
8686
if: ${{ inputs.language == 'go' }}
Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,60 @@
1-
linters-settings:
2-
govet:
3-
enable-all: true
4-
disable:
5-
- fieldalignment
6-
7-
revive:
8-
rules:
9-
- name: var-naming
10-
disabled: true
11-
1+
version: "2"
2+
run:
3+
concurrency: 2
124
linters:
13-
enable-all: true
14-
5+
default: all
156
disable:
16-
- godox
17-
- bodyclose
18-
- contextcheck
19-
- interfacebloat
20-
- gci
21-
- gosmopolitan
22-
- wsl
23-
- varnamelen
24-
- nlreturn
7+
- canonicalheader
8+
- containedctx
9+
- copyloopvar
10+
- cyclop
11+
- depguard
12+
- dupl
13+
- dupword
2514
- err113
26-
- gochecknoglobals
27-
- exhaustruct
2815
- exhaustive
29-
- depguard
30-
- lll
16+
- exhaustruct
3117
- forbidigo
32-
- gochecknoinits
33-
- cyclop
34-
- errorlint
35-
- gomnd
36-
- tagliatelle
37-
- nilnil
38-
- stylecheck
39-
- musttag
40-
- errchkjson
41-
- nonamedreturns
42-
- inamedparam
43-
- ineffassign
44-
- dupword
45-
- nestif
46-
- goconst
4718
- funlen
48-
- dupl
49-
- unparam
19+
- gochecknoglobals
5020
- gocognit
51-
- forcetypeassert
52-
- wastedassign
21+
- goconst
5322
- gocyclo
54-
- maintidx
55-
- copyloopvar
23+
- godoclint
24+
- inamedparam
5625
- intrange
57-
- canonicalheader
26+
- lll
27+
- maintidx
5828
- mnd
29+
- nestif
30+
- nilnil
31+
- nonamedreturns
5932
- perfsprint
60-
- containedctx
61-
62-
# Deprecated
63-
- execinquery
64-
- exportloopref
65-
66-
issues:
67-
exclude-generated: disable
68-
69-
run:
70-
concurrency: 2
71-
timeout: 10m
33+
- recvcheck
34+
- tagliatelle
35+
- varnamelen
36+
- wsl
37+
settings:
38+
govet:
39+
enable-all: true
40+
disable:
41+
- fieldalignment
42+
revive:
43+
rules:
44+
- name: var-naming
45+
disabled: true
46+
staticcheck:
47+
checks: ["all", "-ST1005", "-ST1016"]
48+
exclusions:
49+
generated: disable
50+
presets:
51+
- comments
52+
- std-error-handling
53+
formatters:
54+
enable:
55+
- gofmt
56+
- gofumpt
57+
- golines
58+
settings:
59+
golines:
60+
max-len: 150

clients/algoliasearch-client-go/algolia/debug/debug.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ func Display(input any) {
3030
if !debug {
3131
return
3232
}
33+
3334
start := time.Now()
35+
3436
var msg string
37+
3538
switch v := input.(type) {
3639
case *http.Request:
3740
msg = debugRequest(v)
@@ -40,6 +43,7 @@ func Display(input any) {
4043
default:
4144
msg = fmt.Sprintf("do not know how to display %#v", v)
4245
}
46+
4347
Println(msg)
4448
fmt.Printf("took %s\n", time.Since(start))
4549
}
@@ -52,6 +56,7 @@ func Printf(format string, a ...any) {
5256
if !debug {
5357
return
5458
}
59+
5560
msg := fmt.Sprintf(format, a...)
5661
fmt.Printf("> ALGOLIA DEBUG: %s", msg)
5762
}

clients/algoliasearch-client-go/algolia/debug/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ func copyReadCloser(r io.ReadCloser) (io.ReadCloser, string) {
1616
if r == nil {
1717
return nil, ""
1818
}
19+
1920
data, err := io.ReadAll(r)
2021
_ = r.Close()
22+
2123
if err != nil {
2224
return nil, ""
2325
}
26+
2427
return io.NopCloser(bytes.NewReader(data)), string(data)
2528
}
2629

@@ -29,10 +32,12 @@ func decodeGzipContent(in string) (string, error) {
2932
if err != nil {
3033
return in, fmt.Errorf("cannot open content with gzip.Reader: %w", err)
3134
}
35+
3236
out, err := io.ReadAll(gr)
3337
if err != nil {
3438
return in, fmt.Errorf("cannot read content from gzip.Reader: %w", err)
3539
}
40+
3641
return string(out), nil
3742
}
3843

@@ -58,10 +63,12 @@ func extractBody(body io.ReadCloser, c compression.Compression) (io.ReadCloser,
5863

5964
func prettyPrintJSON(input string) string {
6065
var b bytes.Buffer
66+
6167
err := json.Indent(&b, []byte(input), "\t", " ")
6268
if err != nil {
6369
return input
6470
}
71+
6572
return strings.TrimSuffix(b.String(), "\n")
6673
}
6774

@@ -88,8 +95,10 @@ func debugRequest(req *http.Request) string {
8895
if strings.Contains(strings.ToLower(k), "algolia") {
8996
str = strings.Repeat("*", len(str))
9097
}
98+
9199
msg += fmt.Sprintf("\theader=%s:%q\n", k, str)
92100
}
101+
93102
msg += fmt.Sprintf("\tbody=\n\t%s\n", prettyPrintJSON(body))
94103

95104
return msg
@@ -101,6 +110,7 @@ func debugResponse(res *http.Response) string {
101110
}
102111

103112
var body string
113+
104114
res.Body, body = extractBody(res.Body, compression.NONE)
105115

106116
msg := "> ALGOLIA DEBUG response:\n"

clients/algoliasearch-client-go/algolia/errs/no_more_host_to_try_err.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (e *NoMoreHostToTryError) Error() string {
2727
if len(e.intermediateNetworkErrors) > 0 {
2828
return fmt.Errorf("%s %w", baseErr, errors.Join(e.intermediateNetworkErrors...)).Error()
2929
}
30+
3031
return fmt.Sprintf("%s You can use 'ExposeIntermediateNetworkErrors: true' in the config to investigate.", baseErr)
3132
}
3233

clients/algoliasearch-client-go/algolia/transport/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
type Configuration struct {
1010
AppID string
11-
ApiKey string
11+
ApiKey string //nolint:staticcheck
1212

1313
Hosts []StatefulHost
1414
DefaultHeader map[string]string

clients/algoliasearch-client-go/algolia/transport/retry_strategy.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package transport
22

33
import (
44
"context"
5+
"errors"
56
"net"
67
"strings"
78
"sync"
@@ -13,14 +14,16 @@ import (
1314
type Outcome int
1415

1516
const (
16-
DefaultReadTimeout = 5 * time.Second
17-
DefaultWriteTimeout = 30 * time.Second
18-
1917
Success Outcome = iota
2018
Failure
2119
Retry
2220
)
2321

22+
const (
23+
DefaultReadTimeout = 5 * time.Second
24+
DefaultWriteTimeout = 30 * time.Second
25+
)
26+
2427
type Host struct {
2528
scheme string
2629
host string
@@ -29,6 +32,7 @@ type Host struct {
2932

3033
type RetryStrategy struct {
3134
sync.RWMutex
35+
3236
hosts []StatefulHost
3337
writeTimeout time.Duration
3438
readTimeout time.Duration
@@ -99,16 +103,19 @@ func (s *RetryStrategy) Decide(h Host, code int, err error) Outcome {
99103

100104
if err == nil && is2xx(code) {
101105
s.markUp(h)
106+
102107
return Success
103108
}
104109

105110
if isTimeoutError(err) {
106111
s.markTimeout(h)
112+
107113
return Retry
108114
}
109115

110-
if !(isZero(code) || is4xx(code) || is2xx(code)) || isNetworkError(err) {
116+
if (!isZero(code) && !is4xx(code) && !is2xx(code)) || isNetworkError(err) {
111117
s.markDown(h)
118+
112119
return Retry
113120
}
114121

@@ -119,6 +126,7 @@ func (s *RetryStrategy) markUp(host Host) {
119126
for _, h := range s.hosts {
120127
if h.host == host.host {
121128
h.markUp()
129+
122130
return
123131
}
124132
}
@@ -128,6 +136,7 @@ func (s *RetryStrategy) markTimeout(host Host) {
128136
for _, h := range s.hosts {
129137
if h.host == host.host {
130138
h.markTimeout()
139+
131140
return
132141
}
133142
}
@@ -137,6 +146,7 @@ func (s *RetryStrategy) markDown(host Host) {
137146
for _, h := range s.hosts {
138147
if h.host == host.host {
139148
h.markDown()
149+
140150
return
141151
}
142152
}
@@ -146,7 +156,10 @@ func isNetworkError(err error) bool {
146156
if err == nil {
147157
return false
148158
}
149-
_, ok := err.(net.Error)
159+
160+
var netError net.Error
161+
162+
ok := errors.As(err, &netError)
150163
// We need to ensure that the error is a net.Error but not a
151164
// context.DeadlineExceeded error (which is actually a net.Error), because
152165
// we do not want to consider context.DeadlineExceeded as an error.
@@ -157,6 +170,7 @@ func isTimeoutError(err error) bool {
157170
if err == nil {
158171
return false
159172
}
173+
160174
return strings.Contains(err.Error(), context.DeadlineExceeded.Error())
161175
}
162176

0 commit comments

Comments
 (0)