Skip to content

Commit fff70a7

Browse files
authored
Bump golangci-lint to v2 (#2979)
* Remove errant unicode Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * Bump golangci-lint to latest version Done by bumping the version in the Makefile and running the 'golangci-lint migrate' command go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.1 migrate This yields a number of news error from staticcheck, listed below, which we temporarily ignore pending a fix. ST1005: error strings should not be capitalized ST1023: should omit type .* from declaration; it will be inferred from the right-hand side QF1001: could apply De Morgan's law QF1003: could use tagged switch on .* QF1004: could use strings.ReplaceAll instead QF1004: could merge conditional assignment into variable declaration QF1008: could remove embedded field ".*" from selector QF1011: could omit type .* from declaration; it will be inferred from the right-hand side We also add some additional configuration to remove the limits on the number of issues shown by linters, since this will make fixing these things easier, and remove configuration around concurrency since this will be auto-configured by default. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * lint: Use lowercase error strings Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * lint: Remove redundant type info Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * lint: Prefer switch statements over conditional ladders Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * lint: Simplify conditionals Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * lint: Prefer strings.ReplaceAll to string.Replace with n=-1 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * lint: Remove embedded fields from selectors Signed-off-by: Stephen Finucane <stephenfin@redhat.com> --------- Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 41a6359 commit fff70a7

File tree

22 files changed

+92
-71
lines changed

22 files changed

+92
-71
lines changed

.golangci.yaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1-
run:
2-
concurrency: 2
3-
timeout: 10m0s
1+
version: "2"
2+
output:
3+
formats:
4+
text:
5+
path: stdout
6+
colors: false
7+
issues:
8+
max-same-issues: 0
9+
max-issues-per-linter: 0
410
linters:
11+
exclusions:
12+
generated: lax
13+
presets:
14+
- comments
15+
- common-false-positives
16+
- legacy
17+
- std-error-handling
18+
paths:
19+
- third_party$
20+
- builtin$
21+
- examples$
22+
formatters:
523
enable:
624
- gofmt
7-
output:
8-
formats:
9-
 - format: line-number
10-
 path: stdout
25+
exclusions:
26+
generated: lax
27+
paths:
28+
- third_party$
29+
- builtin$
30+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $(BUILD_CMDS): $(SOURCES)
8181
test: unit functional
8282

8383
check: work
84-
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4 run --timeout=20m ./...
84+
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.1 run --timeout=20m ./...
8585

8686
unit: work
8787
go test -tags=unit $(shell go list ./... | sed -e '/sanity/ { N; d; }' | sed -e '/tests/ {N; d;}') $(TESTARGS)

pkg/autohealing/cloudprovider/openstack/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func (provider CloudProvider) UpdateHealthStatus(ctx context.Context, masters []
584584
if err != nil {
585585
return fmt.Errorf("failed to build health status reason for cluster %s, error: %v", clusterName, err)
586586
}
587-
healthStatusReason := strings.Replace(string(jsonDumps), "\"", "'", -1)
587+
healthStatusReason := strings.ReplaceAll(string(jsonDumps), "\"", "'")
588588

589589
updateOpts := []clusters.UpdateOptsBuilder{
590590
clusters.UpdateOpts{

pkg/autohealing/healthcheck/plugin_endpoint.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ func (check *EndpointCheck) Check(ctx context.Context, node NodeInfo, controller
139139

140140
var client *http.Client
141141
protocol := strings.ToLower(check.Protocol)
142-
if protocol == "https" {
142+
switch protocol {
143+
case "https":
143144
tr := &http.Transport{
144145
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
145146
}
146147
client = &http.Client{Transport: tr, Timeout: time.Second * 5}
147-
} else if protocol == "http" {
148+
case "http":
148149
client = &http.Client{Timeout: time.Second * 5}
149150
}
150151

pkg/csi/cinder/openstack/openstack_volumes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (os *OpenStack) DeleteVolume(ctx context.Context, volumeID string) error {
183183
return err
184184
}
185185
if used {
186-
return fmt.Errorf("Cannot delete the volume %q, it's still attached to a node", volumeID)
186+
return fmt.Errorf("cannot delete the volume %q, it's still attached to a node", volumeID)
187187
}
188188

189189
mc := metrics.NewMetricContext("volume", "delete")
@@ -259,7 +259,7 @@ func (os *OpenStack) WaitDiskAttached(ctx context.Context, instanceID string, vo
259259
})
260260

261261
if wait.Interrupted(err) {
262-
err = fmt.Errorf("Volume %q failed to be attached within the allotted time", volumeID)
262+
err = fmt.Errorf("volume %q failed to be attached within the allotted time", volumeID)
263263
}
264264

265265
return err
@@ -285,14 +285,14 @@ func (os *OpenStack) WaitVolumeTargetStatus(ctx context.Context, volumeID string
285285
}
286286
for _, eState := range volumeErrorStates {
287287
if vol.Status == eState {
288-
return false, fmt.Errorf("Volume is in Error State : %s", vol.Status)
288+
return false, fmt.Errorf("volume is in Error State : %s", vol.Status)
289289
}
290290
}
291291
return false, nil
292292
})
293293

294294
if wait.Interrupted(waitErr) {
295-
waitErr = fmt.Errorf("Timeout on waiting for volume %s status to be in %v", volumeID, tStatus)
295+
waitErr = fmt.Errorf("timeout on waiting for volume %s status to be in %v", volumeID, tStatus)
296296
}
297297

298298
return waitErr
@@ -352,7 +352,7 @@ func (os *OpenStack) WaitDiskDetached(ctx context.Context, instanceID string, vo
352352
})
353353

354354
if wait.Interrupted(err) {
355-
err = fmt.Errorf("Volume %q failed to detach within the allotted time", volumeID)
355+
err = fmt.Errorf("volume %q failed to detach within the allotted time", volumeID)
356356
}
357357

358358
return err

pkg/csi/cinder/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func ParseEndpoint(ep string) (string, string, error) {
8686
return s[0], s[1], nil
8787
}
8888
}
89-
return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
89+
return "", "", fmt.Errorf("invalid endpoint: %v", ep)
9090
}
9191

9292
func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {

pkg/csi/manila/manilaclient/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ func New(ctx context.Context, o *client.AuthOpts, userAgent string, extraUserAge
6666
Availability: o.EndpointType,
6767
})
6868
if err != nil {
69-
return nil, fmt.Errorf("failed to create Manila v2 client: %v", err)
69+
return nil, fmt.Errorf("failed to create manila v2 client: %v", err)
7070
}
7171

7272
// Check client's and server's versions for compatibility
7373

7474
client.Microversion = minimumManilaVersion
7575
if err = validateManilaClient(ctx, client); err != nil {
76-
return nil, fmt.Errorf("Manila v2 client validation failed: %v", err)
76+
return nil, fmt.Errorf("manila v2 client validation failed: %v", err)
7777
}
7878

7979
return &Client{c: client}, nil

pkg/identity/keystone/authenticator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewKeystoner(client *gophercloud.ServiceClient) *Keystoner {
5454

5555
// revive:disable:unexported-return
5656
func (k *Keystoner) GetTokenInfo(ctx context.Context, token string) (*tokenInfo, error) {
57-
k.client.ProviderClient.SetToken(token)
57+
k.client.SetToken(token)
5858
ret := tokens.Get(ctx, k.client, token)
5959

6060
tokenUser, err := ret.ExtractUser()
@@ -94,7 +94,7 @@ func (k *Keystoner) GetTokenInfo(ctx context.Context, token string) (*tokenInfo,
9494
// revive:enable:unexported-return
9595

9696
func (k *Keystoner) GetGroups(ctx context.Context, token string, userID string) ([]string, error) {
97-
k.client.ProviderClient.SetToken(token)
97+
k.client.SetToken(token)
9898
allGroupPages, err := users.ListGroups(k.client, userID).AllPages(ctx)
9999
if err != nil {
100100
return nil, fmt.Errorf("failed to get user groups from Keystone: %v", err)

pkg/identity/keystone/authorizer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func getAllowed(definition string, str string) (sets.Set[string], error) {
6464
} else if strings.Index(definition, "[") == 0 && strings.Index(definition, "]") == (len(definition)-1) {
6565
// "['namespace1', 'namespace2']"
6666
var items []string
67-
if err := json.Unmarshal([]byte(strings.Replace(definition, "'", "\"", -1)), &items); err != nil {
67+
if err := json.Unmarshal([]byte(strings.ReplaceAll(definition, "'", "\"")), &items); err != nil {
6868
klog.V(4).Infof("Skip the permission definition %s", definition)
6969
return nil, fmt.Errorf("")
7070
}
@@ -78,7 +78,7 @@ func getAllowed(definition string, str string) (sets.Set[string], error) {
7878
} else if strings.Index(definition, "!") == 0 && strings.Index(definition, "[") == 1 && strings.Index(definition, "]") == (len(definition)-1) {
7979
// "!['namespace1', 'namespace2']"
8080
var items []string
81-
if err := json.Unmarshal([]byte(strings.Replace(definition[1:], "'", "\"", -1)), &items); err != nil {
81+
if err := json.Unmarshal([]byte(strings.ReplaceAll(definition[1:], "'", "\"")), &items); err != nil {
8282
klog.V(4).Infof("Skip the permission definition %s", definition)
8383
return nil, fmt.Errorf("")
8484
}
@@ -219,8 +219,8 @@ func nonResourceMatches(p policy, a authorizer.Attributes) bool {
219219
}
220220
if *p.NonResourceSpec.NonResourcePath != "*" && *p.NonResourceSpec.NonResourcePath != a.GetPath() &&
221221
// Allow a trailing * subpath match
222-
!(strings.HasSuffix(*p.NonResourceSpec.NonResourcePath, "*") &&
223-
strings.HasPrefix(a.GetPath(), strings.TrimRight(*p.NonResourceSpec.NonResourcePath, "*"))) {
222+
(!strings.HasSuffix(*p.NonResourceSpec.NonResourcePath, "*") ||
223+
!strings.HasPrefix(a.GetPath(), strings.TrimRight(*p.NonResourceSpec.NonResourcePath, "*"))) {
224224
return false
225225
}
226226
allowed := match(p.Match, a)

pkg/identity/keystone/keystone.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ func (k *Auth) Handler(w http.ResponseWriter, r *http.Request) {
265265
return
266266
}
267267

268-
if kind == "TokenReview" {
268+
switch kind {
269+
case "TokenReview":
269270
var token = data["spec"].(map[string]interface{})["token"].(string)
270271
userInfo := k.authenticateToken(ctx, w, r, token, data)
271272

@@ -277,9 +278,9 @@ func (k *Auth) Handler(w http.ResponseWriter, r *http.Request) {
277278
klog.Errorf("an error occurred during data synchronization: %v", err)
278279
}
279280
}
280-
} else if kind == "SubjectAccessReview" {
281+
case "SubjectAccessReview":
281282
k.authorizeToken(w, r, data)
282-
} else {
283+
default:
283284
http.Error(w, fmt.Sprintf("unknown kind/apiVersion %q %q", kind, apiVersion), http.StatusBadRequest)
284285
}
285286
}

0 commit comments

Comments
 (0)