refactor(cmd): migrate sort.Slice to slices.SortFunc (bd-u2sc.2)

Modernize sorting code to use Go 1.21+ slices package:
- Replace sort.Slice with slices.SortFunc across 16 files
- Use cmp.Compare for orderable types (strings, ints)
- Use time.Time.Compare for time comparisons
- Use cmp.Or for multi-field sorting
- Use slices.SortStableFunc where stability matters

Benefits: cleaner 3-way comparison, slightly better performance,
modern idiomatic Go.

Part of GH#692 refactoring epic.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-22 15:39:55 -08:00
parent 82cbd98e50
commit e67712dcd4
16 changed files with 96 additions and 80 deletions

View File

@@ -7,7 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"slices"
"strings"
"time"
@@ -895,15 +895,15 @@ func printDiagnostics(result doctorResult) {
fmt.Println(ui.RenderWarn(ui.IconWarn + " WARNINGS"))
// Sort by severity: errors first, then warnings
sort.Slice(warnings, func(i, j int) bool {
slices.SortStableFunc(warnings, func(a, b doctorCheck) int {
// Errors (statusError) come before warnings (statusWarning)
if warnings[i].Status == statusError && warnings[j].Status != statusError {
return true
if a.Status == statusError && b.Status != statusError {
return -1
}
if warnings[i].Status != statusError && warnings[j].Status == statusError {
return false
if a.Status != statusError && b.Status == statusError {
return 1
}
return false // maintain original order within same severity
return 0 // maintain original order within same severity
})
for i, check := range warnings {