Skip to content

Commit 521d6f0

Browse files
committed
feat(ci): migrate to golangci-lint v2
relates to #7279
1 parent 80b48cc commit 521d6f0

31 files changed

Lines changed: 210 additions & 98 deletions

File tree

core/clients/continuous_refresh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func TestContinuousRefreshTokenConcurrency(t *testing.T) {
212212
AccessToken: newAccessToken,
213213
RefreshToken: refreshToken,
214214
}
215-
responseBody, err := json.Marshal(responseBodyStruct)
215+
responseBody, err := json.Marshal(responseBodyStruct) //nolint:gosec // G117: access_token is a standard field name
216216
if err != nil {
217217
t.Fatalf("Do call: failed to marshal additional response: %v", err)
218218
}
@@ -259,7 +259,7 @@ func TestContinuousRefreshTokenConcurrency(t *testing.T) {
259259
AccessToken: accessTokenSecond,
260260
RefreshToken: refreshToken,
261261
}
262-
responseBody, err := json.Marshal(responseBodyStruct)
262+
responseBody, err := json.Marshal(responseBodyStruct) //nolint:gosec // G117: access_token is a standard field name
263263
if err != nil {
264264
t.Fatalf("Do call: failed request to refresh token: marshal access token response: %v", err)
265265
}

core/clients/key_flow.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (c *KeyFlow) SetToken(accessToken, refreshToken string) error {
183183
c.tokenMutex.Lock()
184184
c.token = &TokenResponseBody{
185185
AccessToken: accessToken,
186-
ExpiresIn: int(exp.Time.Unix()),
186+
ExpiresIn: int(exp.Unix()),
187187
RefreshToken: refreshToken,
188188
Scope: defaultScope,
189189
TokenType: defaultTokenType,
@@ -334,6 +334,7 @@ func (c *KeyFlow) createAccessToken() (err error) {
334334

335335
// createAccessTokenWithRefreshToken creates an access token using
336336
// an existing pre-validated refresh token
337+
//
337338
// Deprecated: This method will be removed in future versions. Access tokens are going to be refreshed without refresh token.
338339
// This will be removed after 2026-07-01.
339340
func (c *KeyFlow) createAccessTokenWithRefreshToken() (err error) {
@@ -391,11 +392,11 @@ func (c *KeyFlow) requestToken(grant, assertion string) (*http.Response, error)
391392
}
392393

393394
payload := strings.NewReader(body.Encode())
394-
req, err := http.NewRequest(http.MethodPost, c.config.TokenUrl, payload)
395+
req, err := http.NewRequest(http.MethodPost, c.config.TokenUrl, payload) //nolint:gosec // G704: Tainted URL is expected here
395396
if err != nil {
396397
return nil, err
397398
}
398399
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
399400

400-
return c.authClient.Do(req)
401+
return c.authClient.Do(req) //nolint:gosec // G704: Tainted URL is expected here
401402
}

core/clients/key_flow_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func TestKeyFlowInit(t *testing.T) {
104104
invalidPrivateKey: true,
105105
wantErr: true,
106106
},
107+
//nolint:gosec // G101: These are only test values
107108
{
108109
name: "ok-custom-token-endpoint",
109110
serviceAccountKey: fixtureServiceAccountKey(func(s *ServiceAccountKeyResponse) {
@@ -462,7 +463,7 @@ func TestKeyFlow_Do(t *testing.T) {
462463
TokenType: "Bearer",
463464
}
464465

465-
if err := json.NewEncoder(res.Body).Encode(token); err != nil {
466+
if err := json.NewEncoder(res.Body).Encode(token); err != nil { //nolint:gosec // G117: access_token is a standard field name
466467
t.Logf("no error is expected, but got %v", err)
467468
}
468469

core/clients/workload_identity_flow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ func (c *WorkloadIdentityFederationFlow) requestToken(clientID, assertion string
213213
body.Set("client_id", clientID)
214214

215215
payload := strings.NewReader(body.Encode())
216-
req, err := http.NewRequest(http.MethodPost, c.config.TokenUrl, payload)
216+
req, err := http.NewRequest(http.MethodPost, c.config.TokenUrl, payload) //nolint:gosec // G704: Tainted URL is expected here
217217
if err != nil {
218218
return nil, err
219219
}
220220
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
221221

222-
return c.authClient.Do(req)
222+
return c.authClient.Do(req) //nolint:gosec // G704: Tainted URL is expected here
223223
}

core/clients/workload_identity_flow_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestWorkloadIdentityFlowRoundTrip(t *testing.T) {
181181
for _, tt := range tests {
182182
t.Run(tt.name, func(t *testing.T) {
183183
authServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
184-
err := r.ParseForm()
184+
err := r.ParseForm() //nolint:gosec // G120: Safe to bypass inside unit tests
185185
if err != nil {
186186
t.Fatalf("failed to parse form: %v", err)
187187
}
@@ -217,7 +217,7 @@ func TestWorkloadIdentityFlowRoundTrip(t *testing.T) {
217217
TokenType: "Bearer",
218218
}
219219

220-
payload, err := json.Marshal(tokenResponse)
220+
payload, err := json.Marshal(tokenResponse) //nolint:gosec // G117: access_token is a standard field name
221221
if err != nil {
222222
t.Fatalf("failed to create token payload: %v", err)
223223
}

core/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ func (sc ServerConfigurations) URL(index int, variables map[string]string) (stri
430430
if !found {
431431
return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues)
432432
}
433-
serverUrl = strings.Replace(serverUrl, "{"+name+"}", value, -1)
433+
serverUrl = strings.ReplaceAll(serverUrl, "{"+name+"}", value)
434434
} else {
435-
serverUrl = strings.Replace(serverUrl, "{"+name+"}", variable.DefaultValue, -1)
435+
serverUrl = strings.ReplaceAll(serverUrl, "{"+name+"}", variable.DefaultValue)
436436
}
437437
}
438438
return serverUrl, nil
@@ -554,7 +554,7 @@ func ConfigureRegion(cfg *Configuration) error {
554554
}
555555
// API is regional (not global)
556556
if containsCaseSensitive(availableRegions, cfg.Region) {
557-
cfgUrl := strings.Replace(servers[0].URL, "{region}", fmt.Sprintf("%s.", cfg.Region), -1)
557+
cfgUrl := strings.ReplaceAll(servers[0].URL, "{region}", fmt.Sprintf("%s.", cfg.Region))
558558
cfg.Servers = ServerConfigurations{
559559
{
560560
URL: cfgUrl,
@@ -574,7 +574,7 @@ func ConfigureRegion(cfg *Configuration) error {
574574
}
575575
// If the url is a template, generated using deprecated config.json, the region variable is replaced
576576
// If the url is already configured, there is no region variable and it remains the same
577-
cfgUrl := strings.Replace(servers[0].URL, "{region}", "", -1)
577+
cfgUrl := strings.ReplaceAll(servers[0].URL, "{region}", "")
578578
cfg.Servers = ServerConfigurations{
579579
{
580580
URL: cfgUrl,

golang-ci.yaml

Lines changed: 78 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,99 @@
11
# This file contains all available configuration options
22
# with their default values.
33

4+
version: "2"
5+
46
# options for analysis running
57
run:
68
# default concurrency is a available CPU number
79
concurrency: 4
8-
9-
# timeout for analysis, e.g. 30s, 5m, default is 1m
10-
timeout: 5m
11-
linters-settings:
12-
goimports:
13-
# put imports beginning with prefix after 3rd-party packages;
14-
# it's a comma-separated list of prefixes
15-
local-prefixes: github.com/stackitcloud/stackit-sdk-go
16-
depguard:
17-
rules:
18-
main:
19-
list-mode: lax # Everything is allowed unless it is denied
20-
deny:
21-
- pkg: "github.com/stretchr/testify"
22-
desc: Do not use a testing framework
23-
misspell:
24-
# Correct spellings using locale preferences for US or UK.
25-
# Default is to use a neutral variety of English.
26-
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
27-
locale: US
28-
golint:
29-
min-confidence: 0.8
30-
gosec:
31-
excludes:
32-
# Suppressions: (see https://github.com/securego/gosec#available-rules for details)
33-
- G104 # "Audit errors not checked" -> which we don't need and is a badly implemented version of errcheck
34-
- G102 # "Bind to all interfaces" -> since this is normal in k8s
35-
- G304 # "File path provided as taint input" -> too many false positives
36-
- G307 # "Deferring unsafe method "Close" on type "io.ReadCloser" -> false positive when calling defer resp.Body.Close()
37-
nakedret:
38-
max-func-lines: 0
39-
revive:
40-
ignore-generated-header: true
41-
severity: error
42-
# https://github.com/mgechev/revive
43-
rules:
44-
- name: errorf
45-
- name: context-as-argument
46-
- name: error-return
47-
- name: increment-decrement
48-
- name: indent-error-flow
49-
- name: superfluous-else
50-
- name: unused-parameter
51-
- name: unreachable-code
52-
- name: atomic
53-
- name: empty-lines
54-
- name: early-return
55-
gocritic:
56-
enabled-tags:
57-
- performance
58-
- style
59-
- experimental
60-
disabled-checks:
61-
- wrapperFunc
62-
- typeDefFirst
63-
- ifElseChain
64-
- dupImport # https://github.com/go-critic/go-critic/issues/845
6510
linters:
6611
enable:
67-
# https://golangci-lint.run/usage/linters/
68-
# default linters
69-
- gosimple
70-
- govet
71-
- ineffassign
72-
- staticcheck
73-
- typecheck
74-
- unused
75-
# additional linters
12+
- bodyclose
13+
- depguard
7614
- errorlint
15+
- forcetypeassert
7716
- gochecknoinits
7817
- gocritic
79-
- gofmt
80-
- goimports
8118
- gosec
8219
- misspell
8320
- nakedret
8421
- revive
85-
- depguard
86-
- bodyclose
8722
- sqlclosecheck
8823
- wastedassign
89-
- forcetypeassert
90-
- errcheck
9124
disable:
9225
- noctx # false positive: finds errors with http.NewRequest that dont make sense
9326
- unparam # false positives
94-
issues:
95-
exclude-use-default: false
96-
exclude-rules:
97-
# This ignores all deprecation warnings in the old wait packages while we have the compatibilty layer in place
98-
- path: ^wait/[^/]+\.go$
99-
linters:
100-
- staticcheck
101-
text: "SA1019:"
102-
go: 1.25
27+
settings:
28+
depguard:
29+
rules:
30+
main:
31+
list-mode: lax # Everything is allowed unless it is denied
32+
deny:
33+
- pkg: github.com/stretchr/testify
34+
desc: Do not use a testing framework
35+
gocritic:
36+
disabled-checks:
37+
- wrapperFunc
38+
- typeDefFirst
39+
- ifElseChain
40+
- dupImport # https://github.com/go-critic/go-critic/issues/845
41+
enabled-tags:
42+
- performance
43+
- style
44+
- experimental
45+
gosec:
46+
excludes:
47+
# Suppressions: (see https://github.com/securego/gosec#available-rules for details)
48+
- G104 # "Audit errors not checked" -> which we don't need and is a badly implemented version of errcheck
49+
- G102 # "Bind to all interfaces" -> since this is normal in k8s
50+
- G304 # "File path provided as taint input" -> too many false positives
51+
- G307 # "Deferring unsafe method "Close" on type "io.ReadCloser" -> false positive when calling defer resp.Body.Close()
52+
misspell:
53+
# Correct spellings using locale preferences for US or UK.
54+
# Default is to use a neutral variety of English.
55+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
56+
locale: US
57+
nakedret:
58+
max-func-lines: 0
59+
revive:
60+
severity: error
61+
# https://github.com/mgechev/revive
62+
rules:
63+
- name: errorf
64+
- name: context-as-argument
65+
- name: error-return
66+
- name: increment-decrement
67+
- name: indent-error-flow
68+
- name: superfluous-else
69+
- name: unused-parameter
70+
- name: unreachable-code
71+
- name: atomic
72+
- name: empty-lines
73+
- name: early-return
74+
exclusions:
75+
generated: lax
76+
rules:
77+
- linters:
78+
- staticcheck
79+
# This ignores all deprecation warnings in the old wait packages while we have the compatibilty layer in place
80+
path: wait/[^/]+\.go$
81+
text: "SA1019:"
82+
paths:
83+
- third_party$
84+
- builtin$
85+
formatters:
86+
enable:
87+
- gofmt
88+
- goimports
89+
settings:
90+
goimports:
91+
# put imports beginning with prefix after 3rd-party packages;
92+
# it's a comma-separated list of prefixes
93+
local-prefixes:
94+
- github.com/stackitcloud/stackit-sdk-go
95+
exclusions:
96+
generated: lax
97+
paths:
98+
- third_party$
99+
- builtin$

scripts/project.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ elif [ "$action" = "tools" ]; then
1616

1717
go mod download
1818

19-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0
19+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2
2020
else
2121
echo "Invalid action: '$action', please use $0 help for help"
2222
fi

services/cdn/wait/wait.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
)
2727

2828
// Interfaces needed for tests
29+
//
2930
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
3031
type APIClientInterface interface {
3132
GetDistributionExecute(ctx context.Context, projectId string, distributionId string) (*cdn.GetDistributionResponse, error)

services/dns/wait/wait.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ const (
2525
)
2626

2727
// Interfaces needed for tests
28+
//
2829
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
2930
type APIClientInterface interface {
3031
GetZoneExecute(ctx context.Context, projectId, zoneId string) (*dns.ZoneResponse, error)
3132
GetRecordSetExecute(ctx context.Context, projectId, zoneId, rrSetId string) (*dns.RecordSetResponse, error)
3233
}
3334

3435
// CreateZoneWaitHandler will wait for zone creation
36+
//
3537
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
3638
func CreateZoneWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[dns.ZoneResponse] {
3739
handler := wait.New(func() (waitFinished bool, response *dns.ZoneResponse, err error) {
@@ -55,6 +57,7 @@ func CreateZoneWaitHandler(ctx context.Context, a APIClientInterface, projectId,
5557
}
5658

5759
// PartialUpdateZoneWaitHandler will wait for zone update
60+
//
5861
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
5962
func PartialUpdateZoneWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[dns.ZoneResponse] {
6063
handler := wait.New(func() (waitFinished bool, response *dns.ZoneResponse, err error) {
@@ -79,6 +82,7 @@ func PartialUpdateZoneWaitHandler(ctx context.Context, a APIClientInterface, pro
7982

8083
// DeleteZoneWaitHandler will wait for zone deletion
8184
// returned interface is nil or *ZoneResponseZone
85+
//
8286
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
8387
func DeleteZoneWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[dns.ZoneResponse] {
8488
handler := wait.New(func() (waitFinished bool, response *dns.ZoneResponse, err error) {
@@ -102,6 +106,7 @@ func DeleteZoneWaitHandler(ctx context.Context, a APIClientInterface, projectId,
102106
}
103107

104108
// CreateRecordWaitHandler will wait for recordset creation
109+
//
105110
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
106111
func CreateRecordSetWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId, rrSetId string) *wait.AsyncActionHandler[dns.RecordSetResponse] {
107112
handler := wait.New(func() (waitFinished bool, response *dns.RecordSetResponse, err error) {
@@ -125,6 +130,7 @@ func CreateRecordSetWaitHandler(ctx context.Context, a APIClientInterface, proje
125130
}
126131

127132
// UpdateRecordWaitHandler will wait for recordset update
133+
//
128134
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
129135
func PartialUpdateRecordSetWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId, rrSetId string) *wait.AsyncActionHandler[dns.RecordSetResponse] {
130136
handler := wait.New(func() (waitFinished bool, response *dns.RecordSetResponse, err error) {
@@ -149,6 +155,7 @@ func PartialUpdateRecordSetWaitHandler(ctx context.Context, a APIClientInterface
149155

150156
// DeleteRecordWaitHandler will wait for deletion
151157
// returned interface is nil or *RecordSetResponse
158+
//
152159
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
153160
func DeleteRecordSetWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId, rrSetId string) *wait.AsyncActionHandler[dns.RecordSetResponse] {
154161
handler := wait.New(func() (waitFinished bool, response *dns.RecordSetResponse, err error) {

0 commit comments

Comments
 (0)