From af3dbfbb4c5d3f65411eca6fec072918e909f175 Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Thu, 25 Sep 2025 13:28:26 +0200 Subject: [PATCH] refactor: make alphabetical sort implementation more intuitive When looking into the implementation to understand behavior, it's very confusing to invert the ordering in relation to how te mental model works. This aligns implementation and mental model of the sort of versions in the end Signed-off-by: Sebastian Di Luzio --- internal/policy/alphabetical.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/policy/alphabetical.go b/internal/policy/alphabetical.go index f588f66c..058516b7 100644 --- a/internal/policy/alphabetical.go +++ b/internal/policy/alphabetical.go @@ -57,10 +57,11 @@ func (p *Alphabetical) Latest(versions []string) (string, error) { } var sorted sort.StringSlice = versions - if p.Order == AlphabeticalOrderDesc { + if p.Order == AlphabeticalOrderAsc { + // Default StringSlice.Sort is ascending sort.Sort(sorted) } else { sort.Sort(sort.Reverse(sorted)) } - return sorted[0], nil + return sorted[len(sorted)-1], nil }