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
- Locate each
sort.Slice call flagged by linter
- Replace with
slices.SortFunc using proper type signature
- Update compare function to match
slices.SortFunc signature
- 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 · ◷
sort.Slice Type-Safety Issues
Finding count: 3 instances where
sort.Sliceshould useslices.SortFuncfor type-safe sorting (detected Jun 11, 2026)Root cause
sort.Sliceuses reflection and accepts an untyped interface{} slice, which bypasses Go's type system. Theslices.SortFunc(added in Go 1.22) provides a type-safe alternative with better performance.Sample diagnostics
Affected files
Minor impact areas (3 functions across codebase):
Remediation approach
sort.Slicecall flagged by linterslices.SortFuncusing proper type signatureslices.SortFuncsignaturemake golint-customto verifyExample refactoring
Notes