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 <skitt@redhat.com>
This commit is contained in:
Stephen Kitt 2025-11-07 09:40:42 +01:00
parent 854e67bb51
commit 55c337637e
No known key found for this signature in database
GPG key ID: 1CC5FA453662A71D
3 changed files with 2 additions and 8 deletions

View file

@ -432,7 +432,6 @@ linters:
- typeSwitchVar
- underef
- unslice
- valSwap
revive:
# Only these rules are enabled.
rules:

View file

@ -253,7 +253,6 @@ linters:
- typeSwitchVar
- underef
- unslice
- valSwap
{{- end}}
revive:
# Only these rules are enabled.

View file

@ -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,