Repository navigation
Add sortbasicslices analyzer for basic sort helpers - #76295
Conversation
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
This comment has been minimized.
This comment has been minimized.
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
What this change does: Adds an analyzer that recommends slices.Sort for three basic sort helpers. It registers and documents the analyzer without enforcing it in CI yet.
Should fix:
- Reuse the existing package selector helper, which already handles aliased imports and shadowed names. This removes duplicate lookup code and leaves one implementation to maintain.
Verdict: Ship.
Lean: -10 lines possible.
Generated by ✂️ Ponytail Reviewer for #76295 · codex · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ⊞ 181
Comment /ponytail to run again
| if !ok { | ||
| return "", false | ||
| } | ||
| pkgIdent, ok := sel.X.(*ast.Ident) |
There was a problem hiding this comment.
Should fix: Replace this package lookup with astutil.IsPkgSelector(pass, sel, "sort"); pkg/linters/internal/astutil/astutil.go already handles aliased imports and shadowed names, so keeping a second copy adds code to maintain. Remove the now-unused go/types import too.
There was a problem hiding this comment.
Reused astutil.IsPkgSelector for sort import resolution in commit 4c70cda.
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
| continue | ||
| } | ||
|
|
||
| pkgLog.Printf("flagging sort.%s call at %s", name, pos) |
There was a problem hiding this comment.
The diagnostic describes sort.Strings, sort.Ints, and sort.Float64s as 'not type-safe', but these APIs are already statically typed. The reason to prefer slices.Sort is the generic/type-safe replacement and unified API, not that the old helpers are unsafe. Please reword this to avoid teaching an incorrect rationale (and update the test expectations), e.g. sort.%s can be replaced with slices.Sort.
There was a problem hiding this comment.
Updated the diagnostic to describe replacement with slices.Sort in commit 4c70cda.
There was a problem hiding this comment.
Found one correctness issue in the user-facing diagnostic: it incorrectly says the existing sort helpers are not type-safe. The inline comment explains the needed wording change. The rest of the analyzer integration and tests look consistent with the surrounding linters. Static review only; tests were not run.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR). 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify that the implementation matches the decision. 🔎 Gate evidence
|
There was a problem hiding this comment.
🟡 Changes recommended
The linter misses dot-imported sort calls and incorrectly labels already type-safe helpers as safety defects.
2 open issues
What changed in this PR
Adds sortbasicslices to gh-aw’s custom Go analyzers to recommend slices.Sort for basic sorting helpers.
Changes:
- Detects
sort.Strings,sort.Ints, andsort.Float64s, including aliased imports, while honoring suppression directives. - Adds diagnostic fixtures covering supported calls, exclusions, parentheses, and shadowed identifiers.
- Registers and documents the analyzer, updates the active count to 94, and defers CI enforcement pending remediation.
| File | Description |
|---|---|
pkg/linters/spec_test.go |
Adds the analyzer to public API checks. |
pkg/linters/sortbasicslices/testdata/src/sortbasicslices/sortbasicslices.go |
Covers diagnostics, exclusions, parentheses, and suppression. |
pkg/linters/sortbasicslices/testdata/src/sortbasicslices/shadowed_identifier.go |
Checks that shadowed names are ignored. |
pkg/linters/sortbasicslices/testdata/src/sortbasicslices/alias_import.go |
Covers aliased imports. |
pkg/linters/sortbasicslices/sortbasicslices.go |
Implements detection and diagnostics without automatic fixes. |
pkg/linters/sortbasicslices/sortbasicslices_test.go |
Runs the analyzer fixtures. |
pkg/linters/registry.go |
Registers the analyzer. |
pkg/linters/README.md |
Documents usage and coverage-gating policy. |
pkg/linters/doc.go |
Updates the analyzer list and count. |
pkg/linters/doc_sync_test.go |
Records deferred CI enforcement. |
Review effort: Balanced (auto)
| sel, ok := astutil.UnwrapParenExpr(call.Fun).(*ast.SelectorExpr) | ||
| if !ok { | ||
| return "", false | ||
| } | ||
| pkgIdent, ok := sel.X.(*ast.Ident) | ||
| if !ok || pass.TypesInfo == nil { | ||
| return "", false | ||
| } | ||
| obj := pass.TypesInfo.ObjectOf(pkgIdent) | ||
| if obj == nil { | ||
| return "", false | ||
| } | ||
| pkgName, ok := obj.(*types.PkgName) | ||
| if !ok || pkgName.Imported().Path() != "sort" { | ||
| return "", false | ||
| } | ||
| switch sel.Sel.Name { | ||
| case "Strings", "Ints", "Float64s": | ||
| return sel.Sel.Name, true |
| } | ||
|
|
||
| pkgLog.Printf("flagging sort.%s call at %s", name, pos) | ||
| pass.ReportRangef(call, "sort.%s is not type-safe; use slices.Sort instead", name) |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /grill-with-docs and /codebase-design. Requesting changes for one stale count and one misleading diagnostic. The tests pass and gofmt is clean.
📋 Key Themes & Highlights
Key Themes
- Stale count:
spec_test.gostill says 93 analyzers. There are 94 entries indocumentedAnalyzers(), 94 README rows, and thedoc.goheader says 94. - Misleading message:
sort.Strings is not type-safeis inaccurate, since these functions already take typed slices and simply callslices.Sortsince Go 1.22. The rationale is modernization. - Duplicate helper (follow-up):
matchSortCallrepeats the logic ofastutil.IsPkgSelector.sortslicehas the same copy. This can be a follow-up.
Positive Highlights
- ✅ Alias resolution and shadowing are covered by testdata (
alias_import.go,shadowed_identifier.go). - ✅
nolint:sortbasicslicessuppression is tested. - ✅ The
notYetEnforcedentry keeps CI green while existing violations exist. Clear reasoning. - ✅ Registry,
doc.go, README, andspec_testwere all updated together.
Validation
go test ./pkg/linters/ ./pkg/linters/sortbasicslices/ ./pkg/linters/sortslice/: passgofmt -l pkg/linters/sortbasicslices: clean
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 6.3K
Comment /matt to run again
| } | ||
|
|
||
| pkgLog.Printf("flagging sort.%s call at %s", name, pos) | ||
| pass.ReportRangef(call, "sort.%s is not type-safe; use slices.Sort instead", name) |
There was a problem hiding this comment.
[/grill-with-docs] This diagnostic says sort.%s is not type-safe, which is inaccurate. sort.Strings, sort.Ints, and sort.Float64s already take typed slices, and since Go 1.22 they just call slices.Sort (see sort/sort.go). The real rationale is modernization, so the message should not claim a safety problem.
💡 Suggested change
Use wording such as sort.%s can be replaced with slices.Sort. The same claim appears in the package comment at the top of sortbasicslices.go and in pkg/linters/README.md line 72. Update the want regexps in testdata/src/sortbasicslices/*.go to match. The sortslice message is accurate because sort.Slice takes any.
@copilot please address this.
There was a problem hiding this comment.
Removed the inaccurate type-safety claim from the diagnostic and related docs in commit 4c70cda.
|
|
||
| // matchSortCall reports whether call is a call to sort.Strings, sort.Ints, or | ||
| // sort.Float64s, including calls through an aliased import. | ||
| func matchSortCall(pass *analysis.Pass, call *ast.CallExpr) (string, bool) { |
There was a problem hiding this comment.
[/codebase-design] matchSortCall repeats astutil.IsPkgSelector(pass, sel, "sort") step for step: the ident, ObjectOf, PkgName, and Imported().Path() checks, including the nil guards. Reusing the shared helper keeps import-alias resolution in one place.
💡 Suggested change
func matchSortCall(pass *analysis.Pass, call *ast.CallExpr) (string, bool) {
sel, ok := astutil.UnwrapParenExpr(call.Fun).(*ast.SelectorExpr)
if !ok || !astutil.IsPkgSelector(pass, sel, "sort") {
return "", false
}
switch sel.Sel.Name {
case "Strings", "Ints", "Float64s":
return sel.Sel.Name, true
default:
return "", false
}
}sortslice has the same copy. Consolidating it can be a follow-up rather than a blocker for this PR.
@copilot please address this.
There was a problem hiding this comment.
Reused astutil.IsPkgSelector instead of duplicating package-import resolution in commit 4c70cda.
|
|
||
| // documentedAnalyzers returns the analyzer subpackages documented in the README | ||
| // "Public API > Subpackages" table. The README documents 92 analyzer | ||
| // "Public API > Subpackages" table. The README documents 93 analyzer |
There was a problem hiding this comment.
[/grill-with-docs] Stale count: this comment says 93, but this PR adds a 94th analyzer subpackage. documentedAnalyzers() has 94 entries, the README subpackage table has 94 rows, and the doc.go header says 94. The diff moved this value from 92 to 93, one short. Change documents 93 to documents 94.
@copilot please address this.
There was a problem hiding this comment.
Updated the documented analyzer count to 94 in commit 4c70cda.
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering. Structured data{
"completed_task": 0,
"head": "3c57287b0bfeb2d3b646c2951694b841c56e590f",
"kind": "requested",
"schema_version": "1",
"state": "66fc4b658da56566910af16f0e4997d61680f75d2d4a392b720f84638ef765c6",
"work": [
"5b5b383018dc4d92b8d5448080407c048748989997d2b819ae0dd2ea839cba88",
"9584ecdaa95e825a6acc3d675bcc661e8a9b8122fb0554b1395689fb28b4ae9c",
"b53d3e75a110bd1d065402793bab198390f7067fb160b6f3f0724629397b5b3b",
"b8b8f18bcbca127162356c84d8a3633f9a6c1a74d735fa0cc030413af55695c6",
"e247a1f9698b253a07ecd3bcf4a1b9270bed1fe17c66f3b8de33d509ea59d315"
],
"workflow": "pr-sous-chef"
}
|
…ort-basic-slices Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |


Add a custom linter that flags
sort.Strings,sort.Ints, andsort.Float64scalls that can use the type-safeslices.Sort.nolint:sortbasicslices. Diagnostics only—no automatic fix.