Skip to content

Add sortbasicslices analyzer for basic sort helpers - #76295

Merged
pelikhan merged 5 commits into
mainfrom
copilot/linter-minersort-basic-slices
Nov 9, 2026
Merged

pelikhan merged 5 commits into
mainfrom
copilot/linter-minersort-basic-slices

Conversation

Copilot AI commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Add a custom linter that flags sort.Strings, sort.Ints, and sort.Float64s calls that can use the type-safe slices.Sort.

  • Behavior: Resolves aliased imports; ignores other sort functions and honors nolint:sortbasicslices. Diagnostics only—no automatic fix.
  • Integration: Register and document the analyzer, update the active count to 94, and defer CI enforcement until existing findings are addressed.
sort.Strings(names) // reported
slices.Sort(names)  // preferred

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Add sortbasicslices linter for sort.Strings/Ints/Float64s Add sortbasicslices analyzer for basic sort helpers Nov 9, 2026
Copilot AI requested a review from gh-aw-bot November 9, 2026 19:00
@pelikhan
pelikhan marked this pull request as ready for review November 9, 2026 19:09
Copilot AI dynamic review requested due to automatic review settings November 9, 2026 19:09
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #76295

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

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.

Generated from PR Specification Reviewer · gpt56 · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #76295

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

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.

Generated from PR Code Quality Reviewer · gpt56 · ~3 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused astutil.IsPkgSelector for sort import resolution in commit 4c70cda.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-09T19:13:19Z
review_event: COMMENT
top_themes: [diagnostic accuracy]
files_reviewed: [pkg/linters/sortbasicslices/sortbasicslices.go, pkg/linters/sortbasicslices/sortbasicslices_test.go, pkg/linters/registry.go, pkg/linters/README.md, pkg/linters/doc.go, pkg/linters/doc_sync_test.go, pkg/linters/spec_test.go]
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the diagnostic to describe replacement with slices.Sort in commit 4c70cda.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/76295-add-sortbasicslices-analyzer.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff.

  2. Complete the missing sections. Add context the AI could not infer, refine the decision rationale, and confirm the alternatives. The Deciders field is still marked [TODO: verify].

  3. Commit the finalized ADR to docs/adr/ on your branch.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-76295: Add sortbasicslices Analyzer for Basic Sort Helpers (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and verify that the implementation matches the decision.

🔎 Gate evidence
  • Label: no implementation label (Condition A not met).
  • Volume: 181 added lines in business logic directories (pkg/), above the 100-line threshold (Condition B met). Default directories were used because no .design-gate.yml was found.
  • ADR search: no ADR in the PR body, on the branch (no docs/adr/ file for PR 76295), or in linked issue [linter-miner] Add sortbasicslices linter for sort.Strings/Ints/Float64s #76288 (Fixes #76288). That issue is a linter-miner summary without Context, Decision, Alternatives, or Consequences sections.
  • Naming: the PR number (76295) has five digits, so it is used as-is, matching existing files such as docs/adr/76272-....

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 8.6K · ◷
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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, and sort.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)

Comment on lines +64 to +82
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)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go still says 93 analyzers. There are 94 entries in documentedAnalyzers(), 94 README rows, and the doc.go header says 94.
  • Misleading message: sort.Strings is not type-safe is inaccurate, since these functions already take typed slices and simply call slices.Sort since Go 1.22. The rationale is modernization.
  • Duplicate helper (follow-up): matchSortCall repeats the logic of astutil.IsPkgSelector. sortslice has 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:sortbasicslices suppression is tested.
  • ✅ The notYetEnforced entry keeps CI green while existing violations exist. Clear reasoning.
  • ✅ Registry, doc.go, README, and spec_test were all updated together.

Validation

  • go test ./pkg/linters/ ./pkg/linters/sortbasicslices/ ./pkg/linters/sortslice/: pass
  • gofmt -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused astutil.IsPkgSelector instead of duplicating package-import resolution in commit 4c70cda.

Comment thread pkg/linters/spec_test.go Outdated

// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the documented analyzer count to 94 in commit 4c70cda.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/linters/sortbasicslices/sortbasicslices.go:68): address unresolved feedback - Review comment
  3. Review (pkg/linters/sortbasicslices/sortbasicslices.go:54): address unresolved feedback - Review comment
  4. Review (pkg/linters/sortbasicslices/sortbasicslices.go:55): address unresolved feedback - Review comment
  5. Review (pkg/linters/sortbasicslices/sortbasicslices.go:63): address unresolved feedback - Review comment
  6. Review (pkg/linters/spec_test.go:123): address unresolved feedback - Review comment

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"
}

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~9 AIC · ⌖ ~26 AIC · ⊞ 1.3K · ◷
Comment /souschef to run again

…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>
@pelikhan
pelikhan merged commit e39ba40 into main Nov 9, 2026
91 checks passed
@pelikhan
pelikhan deleted the copilot/linter-minersort-basic-slices branch November 9, 2026 22:08
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[linter-miner] Add sortbasicslices linter for sort.Strings/Ints/Float64s

4 participants