Skip to content

[lint-monster] chore: Replace sort.Slice with slices.SortFunc for type-safety (3 issues) #38494

Description

@github-actions

sort.Slice Type-Safety Issues

Finding count: 3 instances where sort.Slice should use slices.SortFunc for type-safe sorting (detected Jun 11, 2026)

Root cause

sort.Slice uses reflection and accepts an untyped interface{} slice, which bypasses Go's type system. The slices.SortFunc (added in Go 1.22) provides a type-safe alternative with better performance.

Sample diagnostics

sort.Slice is not type-safe; use slices.SortFunc instead

Affected files

Minor impact areas (3 functions across codebase):

  • Scattered instances in workflow/cli/parser packages

Remediation approach

  1. Locate each sort.Slice call flagged by linter
  2. Replace with slices.SortFunc using proper type signature
  3. Update compare function to match slices.SortFunc signature
  4. Run make golint-custom to verify

Example refactoring

// Before
sort.Slice(items, func(i, j int) bool {
  return items[i] < items[j]
})

// After
slices.SortFunc(items, func(a, b Item) int {
  if a < b { return -1 }
  if a > b { return 1 }
  return 0
})

Notes

  • Low-risk change: minimal logic updates needed
  • Improves code maintainability and type safety
  • Improves runtime performance via static typing
  • Requires Go 1.22+ (check go.mod for version requirements)

Generated by 🧌 LintMonster · 216.7 AIC · ⌖ 41.3 AIC · ⊞ 20.2K ·

  • expires on Jun 17, 2026, 7:54 PM UTC-08:00

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions