Use slices.Sort instead of sort.Slice.

There were only two instances of this in the entire code-base. Hence,
I have enabled the modernize rule/linter in golangci-lint.
This commit is contained in:
Mads Jensen
2026-02-05 16:39:13 +01:00
parent ca0c2c50bd
commit 95616cecda
4 changed files with 3 additions and 22 deletions

View File

@@ -597,14 +597,6 @@ linters:
# A useful hint because it can make code more obvious
# and/or avoid helper functions.
- slicescontains
# Replace sort.Slice with slices.Sort for basic types.
#
# A useful hint because the code becomes shorter.
- slicessort
# Use iterators instead of Len/At-style APIs.
#
# A useful hint because the code becomes shorter.
- stditerators
# Replace HasPrefix/TrimPrefix with CutPrefix.
#
# A useful hint because the code becomes shorter.

View File

@@ -333,14 +333,6 @@ linters:
# A useful hint because it can make code more obvious
# and/or avoid helper functions.
- slicescontains
# Replace sort.Slice with slices.Sort for basic types.
#
# A useful hint because the code becomes shorter.
- slicessort
# Use iterators instead of Len/At-style APIs.
#
# A useful hint because the code becomes shorter.
- stditerators
# Replace HasPrefix/TrimPrefix with CutPrefix.
#
# A useful hint because the code becomes shorter.

View File

@@ -17,6 +17,7 @@ limitations under the License.
package cache
import (
"slices"
"sort"
"sync"
@@ -195,9 +196,7 @@ func (c *volumeCache) dump(logger klog.Logger) {
for volumeID := range c.volumes {
volumeIDs = append(volumeIDs, volumeID)
}
sort.Slice(volumeIDs, func(i, j int) bool {
return volumeIDs[i] < volumeIDs[j]
})
slices.Sort(volumeIDs)
for _, volumeID := range volumeIDs {
volume := c.volumes[volumeID]
logger.Info("Cached volume", "volume", volumeID, "csiDriver", volume.csiDriver)

View File

@@ -419,9 +419,7 @@ func createRequestsAndMappings(pod *v1.Pod, extendedResources map[v1.ResourceNam
for resource := range extendedResources {
resourceNames = append(resourceNames, resource)
}
sort.Slice(resourceNames, func(i, j int) bool {
return resourceNames[i] < resourceNames[j]
})
slices.Sort(resourceNames)
for _, resource := range resourceNames {
class := deviceClassMapping.GetDeviceClass(resource)