Skip to content

fix(clippy): use sort_by_key with Reverse for descending sorts - #23

Merged
mateodelnorte merged 1 commit into
mainfrom
meta-cli-clippy
Apr 26, 2026
Merged

mateodelnorte merged 1 commit into
mainfrom
meta-cli-clippy

Conversation

@mateodelnorte

@mateodelnorte mateodelnorte commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Rust 1.95.0 added the unnecessary_sort_by lint, which fires on sort_by(|a, b| b.cmp(&a)) patterns since they're equivalent to sort_by_key(|x| std::cmp::Reverse(x)). Three call sites were caught when meta's CI re-ran for the first time in two weeks against this repo's cloned main.

Changes (mechanical, matches clippy's suggested fix exactly):

  • src/agent_guard.rs:275 — pattern compile-time sort by priority
  • src/agent_score.rs:119 — session list sort by mtime
  • src/dependency_graph.rs:410 — dependent count sort

No functional change — sort order is preserved.

Why this matters now

gitkb/meta#78 (adding Discord release notification) is blocked on clippy. Meta's CI clones this repo's main fresh, so this needs to land first to unblock the meta PR.

Test plan

  • CI clippy passes (verifies the lint fix locally — full workspace clippy needs sibling repos which weren't in scope)

Summary by CodeRabbit

  • Refactor
    • Enhanced internal code quality through optimized sorting implementations across pattern compilation, session management, and dependency analysis systems. All existing functionality is preserved with no impact to user-facing features.

Rust 1.95.0 added the unnecessary_sort_by lint, which fires on
`sort_by(|a, b| b.cmp(&a))` patterns since they are equivalent to
`sort_by_key(|x| std::cmp::Reverse(x))`. This was caught when meta's
CI re-ran for the first time in two weeks (clippy is run with -D warnings
against the cloned meta_cli main).

No functional change — sort order is preserved.
@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 112b1288-0a27-4ee0-8295-856f6fc095ea

📥 Commits

Reviewing files that changed from the base of the PR and between 1286eda and ce3a5dc.

📒 Files selected for processing (3)
  • src/agent_guard.rs
  • src/agent_score.rs
  • src/dependency_graph.rs

Walkthrough

Three sorting implementations across distinct modules were refactored from sort_by with manual comparators to sort_by_key with std::cmp::Reverse, maintaining descending order semantics. No behavioral changes occurred.

Changes

Cohort / File(s) Summary
Sorting refactoring
src/agent_guard.rs, src/agent_score.rs, src/dependency_graph.rs
Simplified descending-order sort implementations by replacing sort_by with manual comparators (b.cmp(&a)) with sort_by_key using std::cmp::Reverse. Affects pattern priority ordering, session transcript modification times, and dependency counts respectively.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

Sorts that once were long and grand,
Now with Reverse take their stand—
Three brief lines of rabbit cheer,
Cleaner code, more crystal clear! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: replacing sort_by comparators with sort_by_key using Reverse for descending sorts across three files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch meta-cli-clippy

Comment @coderabbitai help to get the list of available commands and usage tips.

@mateodelnorte
mateodelnorte merged commit b3e74c1 into main Apr 26, 2026
7 checks passed
@mateodelnorte
mateodelnorte deleted the meta-cli-clippy branch April 26, 2026 21:23
mateodelnorte added a commit to gitkb/meta_git_lib that referenced this pull request Apr 26, 2026
Caught by Rust 1.95.0's unnecessary_sort_by lint. Same pattern as
gitkb/meta_cli#23 — `sort_by(|a, b| b.cmp(&a))` is equivalent to
`sort_by_key(|x| std::cmp::Reverse(x))`. DateTime<Utc> is Copy, so
no allocation/clone concerns.

Unblocks gitkb/meta#78.
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.

1 participant