From 55c337637e4572469aa8bd69f520ec9808b83a2c Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 7 Nov 2025 09:40:42 +0100 Subject: [PATCH] Enforce Golang a, b = b, a swaps This eliminates the last two remaining three-step value swaps (t = a; a = b; b = t instead of a, b = b, a) and enables linting to prevent new ones being added in future. Signed-off-by: Stephen Kitt --- hack/golangci.yaml | 1 - hack/golangci.yaml.in | 1 - .../k8s.io/apimachinery/pkg/util/strategicpatch/patch.go | 8 ++------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/hack/golangci.yaml b/hack/golangci.yaml index fa853d4afa5..a36509859d7 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -432,7 +432,6 @@ linters: - typeSwitchVar - underef - unslice - - valSwap revive: # Only these rules are enabled. rules: diff --git a/hack/golangci.yaml.in b/hack/golangci.yaml.in index 13da763a9a8..a8adbf4b014 100644 --- a/hack/golangci.yaml.in +++ b/hack/golangci.yaml.in @@ -253,7 +253,6 @@ linters: - typeSwitchVar - underef - unslice - - valSwap {{- end}} revive: # Only these rules are enabled. diff --git a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go index 6825a808e67..71f6b5e875c 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go @@ -1827,9 +1827,7 @@ func (ss SortableSliceOfMaps) Less(i, j int) bool { } func (ss SortableSliceOfMaps) Swap(i, j int) { - tmp := ss.s[i] - ss.s[i] = ss.s[j] - ss.s[j] = tmp + ss.s[i], ss.s[j] = ss.s[j], ss.s[i] } func deduplicateAndSortScalars(s []interface{}) []interface{} { @@ -1875,9 +1873,7 @@ func (ss SortableSliceOfScalars) Less(i, j int) bool { } func (ss SortableSliceOfScalars) Swap(i, j int) { - tmp := ss.s[i] - ss.s[i] = ss.s[j] - ss.s[j] = tmp + ss.s[i], ss.s[j] = ss.s[j], ss.s[i] } // Returns the type of the elements of N slice(s). If the type is different,