You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sortslice precision: match sort.Slice/SliceStable via package identity (pass.TypesInfo), not the syntactic identifier name "sort
[Content truncated due to length] #38029
The new sortslice analyzer decides whether a X.Slice(...) / X.SliceStable(...) call targets the stdlib sort package purely by the syntactic identifier textX == "sort". It never consults pass.TypesInfo to confirm X actually resolves to the imported sort package. This makes sortslice the only package-matching custom linter that skips type-based package verification, so it is simultaneously prone to false positives (shadowing) and false negatives (aliased import).
Location:pkg/linters/sortslice/sortslice.go:54-57
Type: Analyzer precision / self-inconsistency with sibling linters
This is a string comparison on the identifier name only. Two concrete defects follow:
False positive (forward-looking robustness): any value named sort with a Slice/SliceStable method is flagged even though it has nothing to do with the stdlib. Example that would be wrongly reported:
sort:=newSorter() // a local of some custom typesort.Slice(items, less) // FALSE POSITIVE: not the stdlib sort package
Likewise a non-stdlib package aliased to the name sort (import sort "example.com/mysort") is wrongly flagged.
False negative: the stdlib sort package imported under an alias is silently missed:
import stdsort "sort"stdsort.Slice(items, less) // FALSE NEGATIVE: real sort.Slice, not flagged
Self-inconsistency: every other custom linter that matches a stdlib-package call resolves the package via pass.TypesInfo and compares the import path, not the spelled name:
This removes the FP on shadowing identifiers and the FN on aliased imports in one change, and brings sortslice in line with the rest of the linter suite. (sortslice already builds with inspect, so pass.TypesInfo is available.)
Validation checklist
Add testdata cases: stdlib sort under an alias (import s "sort"; s.Slice(...)) — want diagnostic; a non-sort identifier named sort calling .Slice(...) — no diagnostic
Existing sort.Strings/sort.Ints good cases still pass
go test ./pkg/linters/sortslice/... green
Effort: Small (single-file precision fix + 2 testdata cases). Mirrors prior single-file precision fixes that landed within ~1 day (e.g. #37741, #37492).
Activity