modernize: slicescontains

go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest
    modernize -slicescontains -fix ./...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-02-11 13:35:26 +01:00
parent 835d510b78
commit 6d4b3b5f66
7 changed files with 31 additions and 37 deletions
+6 -4
View File
@@ -1,9 +1,13 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24
package manifest
import (
"context"
"fmt"
"path/filepath"
"slices"
"github.com/containerd/errdefs"
"github.com/docker/cli/cli"
@@ -164,10 +168,8 @@ func runManifestAnnotate(dockerCLI command.Cli, opts annotateOptions) error {
}
func appendIfUnique(list []string, str string) []string {
for _, s := range list {
if s == str {
return list
}
if slices.Contains(list, str) {
return list
}
return append(list, str)
}
+1 -6
View File
@@ -552,12 +552,7 @@ func updateStringToSlice(flags *pflag.FlagSet, flag string, field *[]string) {
}
func anyChanged(flags *pflag.FlagSet, fields ...string) bool {
for _, flag := range fields {
if flags.Changed(flag) {
return true
}
}
return false
return slices.ContainsFunc(fields, flags.Changed)
}
func addGenericResources(flags *pflag.FlagSet, spec *swarm.TaskSpec) error {
+6 -4
View File
@@ -1,3 +1,6 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24
// Package connhelper provides helpers for connecting to a remote daemon host with custom logic.
package connhelper
@@ -6,6 +9,7 @@ import (
"fmt"
"net"
"net/url"
"slices"
"strings"
"github.com/docker/cli/cli/connhelper/commandconn"
@@ -89,10 +93,8 @@ func addSSHTimeout(sshFlags []string) []string {
// disablePseudoTerminalAllocation disables pseudo-terminal allocation to
// prevent SSH from executing as a login shell
func disablePseudoTerminalAllocation(sshFlags []string) []string {
for _, flag := range sshFlags {
if flag == "-T" {
return sshFlags
}
if slices.Contains(sshFlags, "-T") {
return sshFlags
}
return append(sshFlags, "-T")
}
+6 -4
View File
@@ -1,3 +1,6 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24
package main
import (
@@ -7,6 +10,7 @@ import (
"os"
"os/exec"
"os/signal"
"slices"
"strings"
"syscall"
@@ -617,10 +621,8 @@ func findCommand(cmd *cobra.Command, cmds []string) bool {
if cmd == nil {
return false
}
for _, c := range cmds {
if c == cmd.Name() {
return true
}
if slices.Contains(cmds, cmd.Name()) {
return true
}
return findCommand(cmd.Parent(), cmds)
}
+2 -6
View File
@@ -6,6 +6,7 @@ package volumespec
import (
"errors"
"fmt"
"slices"
"strings"
"unicode"
"unicode/utf8"
@@ -89,12 +90,7 @@ func populateFieldFromBuffer(char rune, buffer []rune, volume *VolumeConfig) err
}
func isBindOption(option string) bool {
for _, propagation := range mount.Propagations {
if mount.Propagation(option) == propagation {
return true
}
}
return false
return slices.Contains(mount.Propagations, mount.Propagation(option))
}
func populateType(volume *VolumeConfig) {
+5 -6
View File
@@ -1,3 +1,6 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24
package opts
import (
@@ -7,6 +10,7 @@ import (
"math/big"
"net"
"path"
"slices"
"strings"
"github.com/docker/cli/internal/lazyregexp"
@@ -104,12 +108,7 @@ func (opts *ListOpts) GetAllOrEmpty() []string {
// Get checks the existence of the specified key.
func (opts *ListOpts) Get(key string) bool {
for _, k := range *opts.values {
if k == key {
return true
}
}
return false
return slices.Contains(*opts.values, key)
}
// Len returns the amount of element in the slice.
+5 -7
View File
@@ -1,8 +1,12 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24
package swarmopts
import (
"bytes"
"os"
"slices"
"testing"
"github.com/docker/go-connections/nat"
@@ -371,13 +375,7 @@ func TestConvertPortToPortConfigWithIP(t *testing.T) {
func assertContains(t *testing.T, portConfigs []swarm.PortConfig, expected swarm.PortConfig) {
t.Helper()
contains := false
for _, portConfig := range portConfigs {
if portConfig == expected {
contains = true
break
}
}
contains := slices.Contains(portConfigs, expected)
if !contains {
t.Errorf("expected %v to contain %v, did not", portConfigs, expected)
}