Skip to content

refactor: apply cargo clippy fixes to improve code quality#16

Merged
yejiming merged 1 commit into
yejiming:mainfrom
whitelonng:fix/11-16-config-cleanup
Jun 21, 2026
Merged

refactor: apply cargo clippy fixes to improve code quality#16
yejiming merged 1 commit into
yejiming:mainfrom
whitelonng:fix/11-16-config-cleanup

Conversation

@whitelonng

Copy link
Copy Markdown
Contributor

Summary

Applied cargo clippy suggestions to improve code quality and maintainability, reducing warnings from 27 to 2.

Changes

Automatic Fixes (20 suggestions)

  • ✅ Redundant return statements removed
  • ✅ Collapsible if statements simplified
  • ✅ Iterator optimizations (replaced .last() on DoubleEndedIterator)
  • ✅ Unnecessary borrows removed
  • ✅ Manual implementations of standard methods replaced
  • ✅ Other idiomatic Rust patterns applied

Manual Fixes (7 suggestions)

  1. Remove unused import: Manager from lib.rs
  2. Replace sort_by with sort_by_key for cleaner sorting:
    // Before
    summaries.sort_by(|a, b| b.saved_at.cmp(&a.saved_at));
    
    // After
    summaries.sort_by_key(|s| std::cmp::Reverse(s.saved_at));
  3. Replace manual loop counter with enumerate():
    // Before
    let mut kept = 0;
    for index in (0..history.len()).rev() {
        kept += 1;
    }
    
    // After
    for (kept, index) in (0..history.len()).rev().enumerate() {
    }
  4. Collapse nested if let into single pattern:
    // Before
    if let Some(event) = parse_event(data) {
        if let Event::Text(delta) = event {
    
    // After
    if let Some(Event::Text(delta)) = parse_event(data) {

Remaining Warnings (2)

Two "too many arguments" warnings remain for functions that would require larger refactoring:

  1. call_background_llm (11 parameters) in agent/sessions.rs
  2. emit_tool_event (9 parameters) in agent/mod.rs

These functions are candidates for future refactoring using parameter structs, but are deferred to avoid large changes affecting multiple call sites in this PR.

Benefits

  • ✅ More idiomatic Rust code
  • ✅ Better performance (iterator optimizations)
  • ✅ Improved readability and maintainability
  • ✅ 92% reduction in clippy warnings (27 → 2)

Test Plan

  • ✅ 186 Rust unit tests pass
  • ✅ TypeScript type check passes
  • All fixes verified to maintain existing functionality

@whitelonng whitelonng force-pushed the fix/11-16-config-cleanup branch 2 times, most recently from d7b400a to c157261 Compare June 21, 2026 12:46
Applied clippy suggestions to improve code quality and maintainability,
reducing warnings from 27 to 2.

Changes:
- Remove unused import: Manager from lib.rs
- Replace sort_by with sort_by_key using Reverse for cleaner sorting
  - mobile_server.rs: session list sorting
  - agent/sessions.rs: session list sorting
- Replace manual loop counter with enumerate() in llm/mod.rs
- Collapse nested if let into single pattern match in book_travel.rs
- Apply 20 automatic clippy fixes for:
  - Redundant return statements
  - Collapsible if statements
  - Iterator optimizations (replace .last() on DoubleEndedIterator)
  - Unnecessary borrows
  - Manual implementations of standard methods
  - Other idiomatic Rust patterns

Remaining warnings (2):
Two "too many arguments" warnings remain for functions that would require
larger refactoring to use parameter structs:
- call_background_llm (11 params) in agent/sessions.rs
- emit_tool_event (9 params) in agent/mod.rs

These are candidates for future refactoring but are deferred to avoid
large changes affecting multiple call sites.

Test results:
- ✅ 186 Rust unit tests pass
- ✅ TypeScript type check passes
@yejiming yejiming force-pushed the fix/11-16-config-cleanup branch from c157261 to afdc46f Compare June 21, 2026 14:13
@yejiming yejiming merged commit 7d8ca8b into yejiming:main Jun 21, 2026
1 of 2 checks passed
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.

2 participants