Skip to content

Commit 2d194dc

Browse files
authored
Merge pull request #6789 from thaJeztah/bump_golangci_lint
Dockerfile: update golangci-lint to v2.9.0 and fix linting
2 parents 9a41c73 + a934c75 commit 2d194dc

18 files changed

Lines changed: 45 additions & 42 deletions

File tree

cli-plugins/manager/cobra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func AddPluginCommandStubs(dockerCLI config.Provider, rootCmd *cobra.Command) (e
5757
},
5858
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
5959
// Delegate completion to plugin
60-
cargs := []string{p.Path, cobra.ShellCompRequestCmd, p.Name}
60+
cargs := []string{p.Path, cobra.ShellCompRequestCmd, p.Name} //nolint:prealloc // no need to over-complicate things.
6161
cargs = append(cargs, args...)
6262
cargs = append(cargs, toComplete)
6363
os.Args = cargs

cli/command/formatter/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func DisplayablePorts(ports []container.PortSummary) string {
350350
last uint16
351351
}
352352
groupMap := make(map[string]*portGroup)
353-
var result []string //nolint:prealloc
353+
var result []string
354354
var hostMappings []string
355355
var groupMapKeys []string
356356
sort.Slice(ports, func(i, j int) bool {

cli/command/image/build_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (f *fakeBuild) build(_ context.Context, buildContext io.Reader, options cli
190190

191191
func (f *fakeBuild) headers(t *testing.T) []*tar.Header {
192192
t.Helper()
193-
headers := []*tar.Header{}
193+
var headers []*tar.Header
194194
for {
195195
hdr, err := f.context.Next()
196196
switch err {
@@ -206,8 +206,9 @@ func (f *fakeBuild) headers(t *testing.T) []*tar.Header {
206206

207207
func (f *fakeBuild) filenames(t *testing.T) []string {
208208
t.Helper()
209-
names := []string{}
210-
for _, header := range f.headers(t) {
209+
h := f.headers(t)
210+
names := make([]string, 0, len(h))
211+
for _, header := range h {
211212
names = append(names, header.Name)
212213
}
213214
sort.Strings(names)

cli/command/service/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestServiceListServiceStatus(t *testing.T) {
108108
},
109109
}
110110

111-
matrix := make([]testCase, 0)
111+
matrix := make([]testCase, 0, len(tests))
112112
for _, quiet := range []bool{false, true} {
113113
for _, tc := range tests {
114114
if quiet {

cli/command/service/progress/progress_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
8080
service: service,
8181
}
8282

83-
tasks := []swarm.Task{}
83+
var tasks []swarm.Task //nolint:prealloc // no need to over-complicate things.
8484

8585
ut.testUpdater(tasks, false,
8686
[]progress.Progress{
@@ -193,7 +193,7 @@ func TestReplicatedProgressUpdaterManyReplicas(t *testing.T) {
193193
service: service,
194194
}
195195

196-
tasks := []swarm.Task{}
196+
var tasks []swarm.Task
197197

198198
// No per-task progress bars because there are too many replicas
199199
ut.testUpdater(tasks, false,
@@ -248,7 +248,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
248248
service: service,
249249
}
250250

251-
tasks := []swarm.Task{}
251+
var tasks []swarm.Task //nolint:prealloc // no need to over-complicate things.
252252

253253
ut.testUpdater(tasks, false,
254254
[]progress.Progress{
@@ -362,7 +362,7 @@ func TestGlobalProgressUpdaterManyNodes(t *testing.T) {
362362
ut.activeNodes[strconv.Itoa(i)] = struct{}{}
363363
}
364364

365-
tasks := []swarm.Task{}
365+
var tasks []swarm.Task
366366

367367
ut.testUpdater(tasks, false,
368368
[]progress.Progress{
@@ -459,25 +459,24 @@ func TestReplicatedJobProgressUpdaterSmall(t *testing.T) {
459459
})
460460

461461
// wipe the old tasks out of the list
462-
tasks = []swarm.Task{}
463-
tasks = append(tasks,
464-
swarm.Task{
462+
tasks = []swarm.Task{ //nolint:prealloc // no need to over-complicate things.
463+
{
465464
ID: "task1",
466465
Slot: 0,
467466
NodeID: "",
468467
DesiredState: swarm.TaskStateComplete,
469468
Status: swarm.TaskStatus{State: swarm.TaskStateNew},
470469
JobIteration: &swarm.Version{Index: service.JobStatus.JobIteration.Index},
471470
},
472-
swarm.Task{
471+
{
473472
ID: "task2",
474473
Slot: 1,
475474
NodeID: "",
476475
DesiredState: swarm.TaskStateComplete,
477476
Status: swarm.TaskStatus{State: swarm.TaskStateNew},
478477
JobIteration: &swarm.Version{Index: service.JobStatus.JobIteration.Index},
479478
},
480-
)
479+
}
481480
ut.testUpdater(tasks, false, []progress.Progress{
482481
{ID: "1/5", Action: "new ", Current: 1, Total: 10, HideCounts: true},
483482
{ID: "2/5", Action: "new ", Current: 1, Total: 10, HideCounts: true},
@@ -644,7 +643,7 @@ func TestReplicatedJobProgressUpdaterLarge(t *testing.T) {
644643
service: service,
645644
}
646645

647-
tasks := []swarm.Task{}
646+
var tasks []swarm.Task
648647

649648
// see the comments in TestReplicatedJobProgressUpdaterSmall for why
650649
// we write this out twice.
@@ -741,7 +740,7 @@ func TestGlobalJobProgressUpdaterSmall(t *testing.T) {
741740
service: service,
742741
}
743742

744-
tasks := []swarm.Task{
743+
tasks := []swarm.Task{ //nolint:prealloc // no need to over-complicate things.
745744
{
746745
ID: "oldtask1",
747746
DesiredState: swarm.TaskStateComplete,
@@ -871,7 +870,7 @@ func TestGlobalJobProgressUpdaterLarge(t *testing.T) {
871870
service: service,
872871
}
873872

874-
tasks := []swarm.Task{}
873+
var tasks []swarm.Task //nolint:prealloc // no need to over-complicate things.
875874
for nodeID := range activeNodes {
876875
tasks = append(tasks, swarm.Task{
877876
ID: "task" + nodeID,

cli/command/service/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ func updateNetworks(ctx context.Context, apiClient client.NetworkAPIClient, flag
13231323
}
13241324

13251325
existingNetworks := make(map[string]struct{})
1326-
var newNetworks []swarm.NetworkAttachmentConfig //nolint:prealloc
1326+
var newNetworks []swarm.NetworkAttachmentConfig
13271327
for _, nw := range specNetworks {
13281328
if _, exists := idsToRemove[nw.Target]; exists {
13291329
continue

cli/command/stack/loader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes
2727
return nil, err
2828
}
2929

30-
dicts := getDictsFrom(configDetails.ConfigFiles)
3130
config, err := loader.Load(configDetails)
3231
if err != nil {
3332
var fpe *loader.ForbiddenPropertiesError
@@ -39,6 +38,7 @@ func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes
3938
return nil, err
4039
}
4140

41+
dicts := getDictsFrom(configDetails.ConfigFiles)
4242
unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
4343
if len(unsupportedProperties) > 0 {
4444
_, _ = fmt.Fprintf(streams.Err(), "Ignoring unsupported options: %s\n\n",
@@ -65,8 +65,7 @@ func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes
6565
}
6666

6767
func getDictsFrom(configFiles []composetypes.ConfigFile) []map[string]any {
68-
dicts := []map[string]any{}
69-
68+
dicts := make([]map[string]any, 0, len(configFiles))
7069
for _, configFile := range configFiles {
7170
dicts = append(dicts, configFile.Config)
7271
}

cli/command/swarm/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (*ExternalCAOption) Type() string {
110110

111111
// String returns a string repr of this option.
112112
func (m *ExternalCAOption) String() string {
113-
externalCAs := []string{}
113+
externalCAs := make([]string, 0, len(m.values))
114114
for _, externalCA := range m.values {
115115
repr := fmt.Sprintf("%s: %s", externalCA.Protocol, externalCA.URL)
116116
externalCAs = append(externalCAs, repr)

cli/command/system/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ func prettyPrintEvent(out io.Writer, event events.Message) error {
133133
_, _ = fmt.Fprintf(out, "%s %s %s", event.Type, event.Action, event.Actor.ID)
134134

135135
if len(event.Actor.Attributes) > 0 {
136-
var attrs []string
137-
var keys []string
136+
keys := make([]string, 0, len(event.Actor.Attributes))
138137
for k := range event.Actor.Attributes {
139138
keys = append(keys, k)
140139
}
141140
sort.Strings(keys)
141+
attrs := make([]string, 0, len(keys))
142142
for _, k := range keys {
143143
v := event.Actor.Attributes[k]
144144
attrs = append(attrs, k+"="+v)

cli/compose/convert/service.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ func Service(
174174
}
175175

176176
func getPlacementPreference(preferences []composetypes.PlacementPreferences) []swarm.PlacementPreference {
177-
result := []swarm.PlacementPreference{}
177+
if len(preferences) == 0 {
178+
return nil
179+
}
180+
181+
result := make([]swarm.PlacementPreference, 0, len(preferences))
178182
for _, preference := range preferences {
179183
spreadDescriptor := preference.Spread
180184
result = append(result, swarm.PlacementPreference{
@@ -198,7 +202,7 @@ func convertServiceNetworks(
198202
}
199203
}
200204

201-
nets := []swarm.NetworkAttachmentConfig{}
205+
nets := make([]swarm.NetworkAttachmentConfig, 0, len(networks))
202206
for networkName, nw := range networks {
203207
networkConfig, ok := networkConfigs[networkName]
204208
if !ok && networkName != defaultNetwork {
@@ -241,15 +245,15 @@ func convertServiceSecrets(
241245
secrets []composetypes.ServiceSecretConfig,
242246
secretSpecs map[string]composetypes.SecretConfig,
243247
) ([]*swarm.SecretReference, error) {
244-
refs := []*swarm.SecretReference{}
245-
246248
lookup := func(key string) (composetypes.FileObjectConfig, error) {
247249
secretSpec, exists := secretSpecs[key]
248250
if !exists {
249251
return composetypes.FileObjectConfig{}, fmt.Errorf("undefined secret %q", key)
250252
}
251253
return composetypes.FileObjectConfig(secretSpec), nil
252254
}
255+
256+
refs := make([]*swarm.SecretReference, 0, len(secrets))
253257
for _, secret := range secrets {
254258
obj, err := convertFileObject(namespace, composetypes.FileReferenceConfig(secret), lookup)
255259
if err != nil {
@@ -564,7 +568,7 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement
564568
}
565569

566570
func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) *swarm.EndpointSpec {
567-
portConfigs := []swarm.PortConfig{}
571+
portConfigs := make([]swarm.PortConfig, 0, len(source))
568572
for _, port := range source {
569573
portConfig := swarm.PortConfig{
570574
Protocol: network.IPProtocol(port.Protocol),

0 commit comments

Comments
 (0)