Skip to content

Commit a271438

Browse files
chore: address golangci 2.7.0 and modernize findings (#614)
Big PR, but the bulk of it are modernize's `interface{}` to `any` autofixes. --------- Co-authored-by: Ville Välimäki <ville.valimaki@upcloud.com>
1 parent a73072a commit a271438

Some content is hidden

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

61 files changed

+151
-177
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- ineffassign
1919
- makezero
2020
- misspell
21+
- modernize
2122
- nakedret
2223
- nilnil
2324
- nolintlint

internal/commands/account/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (l *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
5050
}, nil
5151
}
5252

53-
func formatRoles(val interface{}) (text.Colors, string, error) {
53+
func formatRoles(val any) (text.Colors, string, error) {
5454
roles, ok := val.([]string)
5555
if !ok {
5656
return nil, "", fmt.Errorf("cannot parse %T, expected []string", val)

internal/commands/account/permissions/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (l *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
7474
}, nil
7575
}
7676

77-
func formatOptions(val interface{}) (text.Colors, string, error) {
77+
func formatOptions(val any) (text.Colors, string, error) {
7878
options, ok := val.(*upcloud.PermissionOptions)
7979
if !ok {
8080
return nil, "", fmt.Errorf("cannot parse %T, expected *upcloud.PermissionOptions", val)

internal/commands/account/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
119119
}, nil
120120
}
121121

122-
func formatCredits(val interface{}) (text.Colors, string, error) {
122+
func formatCredits(val any) (text.Colors, string, error) {
123123
credits, ok := val.(float64)
124124
if !ok {
125125
return nil, "", fmt.Errorf("cannot parse %T, expected float64", val)

internal/commands/account/token/create_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestCreateToken(t *testing.T) {
5555
args: []string{
5656
"--expires-in", "1h",
5757
},
58-
errFn: func(t assert.TestingT, err error, _ ...interface{}) bool {
58+
errFn: func(t assert.TestingT, err error, _ ...any) bool {
5959
return assert.ErrorContains(t, err, `required flag(s) "name" not set`)
6060
},
6161
},
@@ -65,7 +65,7 @@ func TestCreateToken(t *testing.T) {
6565
"--name", "test",
6666
"--expires-in", "seppo",
6767
},
68-
errFn: func(t assert.TestingT, err error, _ ...interface{}) bool {
68+
errFn: func(t assert.TestingT, err error, _ ...any) bool {
6969
return assert.ErrorContains(t, err, `invalid argument "seppo" for "--expires-in"`)
7070
},
7171
},
@@ -75,7 +75,7 @@ func TestCreateToken(t *testing.T) {
7575
"--name", "test",
7676
"--expires-at", "seppo",
7777
},
78-
errFn: func(t assert.TestingT, err error, _ ...interface{}) bool {
78+
errFn: func(t assert.TestingT, err error, _ ...any) bool {
7979
return assert.ErrorContains(t, err, `invalid expires-at: `)
8080
},
8181
},
@@ -84,7 +84,7 @@ func TestCreateToken(t *testing.T) {
8484
args: []string{
8585
"--name", "test",
8686
},
87-
errFn: func(t assert.TestingT, err error, _ ...interface{}) bool {
87+
errFn: func(t assert.TestingT, err error, _ ...any) bool {
8888
return assert.ErrorContains(t, err, `either expires-in or expires-at must be set`)
8989
},
9090
},

internal/commands/all/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
6262
}, nil
6363
}
6464

65-
func formatUUID(val interface{}) (text.Colors, string, error) {
65+
func formatUUID(val any) (text.Colors, string, error) {
6666
str, ok := val.(string)
6767
if !ok {
6868
return nil, "", fmt.Errorf("cannot parse %T, expected string", val)

internal/commands/all/purge_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func TestPurgeCommand(t *testing.T) {
1717
for _, test := range []struct {
1818
name string
1919
args []string
20-
called [][]interface{}
20+
called [][]any
2121
}{
2222
{
2323
name: "purge non-persistent tf-acc-test resources",
2424
args: []string{"--include", "*tf-acc-test*", "--exclude", "*persistent*"},
25-
called: [][]interface{}{
25+
called: [][]any{
2626
{"DeleteManagedObjectStorage", &request.DeleteManagedObjectStorageRequest{
2727
UUID: objectStorages[0].UUID,
2828
}},

internal/commands/all/resource.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ type findResult struct {
126126
}
127127

128128
func findResources[T any](exec commands.Executor, wg *sync.WaitGroup, returnChan chan findResult, r resolver.CachingResolutionProvider[T], include, exclude []string) {
129-
wg.Add(1)
130-
131-
go func() {
132-
defer wg.Done()
129+
wg.Go(func() {
133130
var resources []Resource
134131
matches, err := getMatches(exec, r, include, exclude)
135132
if err != nil {
@@ -145,7 +142,7 @@ func findResources[T any](exec commands.Executor, wg *sync.WaitGroup, returnChan
145142
resources = append(resources, resource)
146143
}
147144
returnChan <- findResult{Resources: resources, Error: nil}
148-
}()
145+
})
149146
}
150147

151148
func ListResources(exec commands.Executor, include, exclude []string) ([]Resource, error) {
@@ -318,7 +315,7 @@ func DeleteResources(exec commands.Executor, resources []Resource, workerCount i
318315
}
319316

320317
workerQueue := make(chan int, workerCount)
321-
for n := 0; n < workerCount; n++ {
318+
for n := range workerCount {
322319
workerQueue <- n
323320
}
324321

internal/commands/command.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commands
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
"strings"
78

89
"github.com/UpCloudLtd/upcloud-cli/v3/internal/completion"
@@ -161,12 +162,7 @@ func (s *BaseCommand) Aliases() []string {
161162

162163
// isDeprecatedAlias checks if an alias is deprecated
163164
func (s *BaseCommand) isDeprecatedAlias(alias string) bool {
164-
for _, deprecated := range s.deprecatedAliases {
165-
if alias == deprecated {
166-
return true
167-
}
168-
}
169-
return false
165+
return slices.Contains(s.deprecatedAliases, alias)
170166
}
171167

172168
func (s *BaseCommand) DeprecatedAliases() []string {

internal/commands/database/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func processProperties(in []string, t *upcloud.ManagedDatabaseType) (request.Man
133133
continue
134134
}
135135

136-
var parsedValue interface{}
136+
var parsedValue any
137137
if err := json.Unmarshal([]byte(value), &parsedValue); err != nil {
138138
resp.Set(key, value) // Set as plain string if parsing fails
139139
} else {
@@ -147,9 +147,9 @@ func processNetworks(in []string) ([]upcloud.ManagedDatabaseNetwork, error) {
147147
var networks []upcloud.ManagedDatabaseNetwork
148148
for _, netStr := range in {
149149
network := upcloud.ManagedDatabaseNetwork{}
150-
pairs := strings.Split(netStr, ",")
150+
pairs := strings.SplitSeq(netStr, ",")
151151

152-
for _, pair := range pairs {
152+
for pair := range pairs {
153153
parts := strings.SplitN(pair, "=", 2)
154154
if len(parts) != 2 {
155155
return nil, fmt.Errorf("invalid network format: %s, expected key=value", pair)

0 commit comments

Comments
 (0)