From 6b90c7eb0d17d9281a377454e76dcc88a4232bc7 Mon Sep 17 00:00:00 2001 From: "Cyrene (Mem)" Date: Wed, 22 Jul 2026 14:16:49 +0700 Subject: [PATCH] fix(rust): resolve all clippy warnings treated as errors in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix 18 clippy errors across 7 files: - lib.rs: change doc comment to regular comment (empty line after doc) - arch_audit.rs: replace format!() with string literal, use is_none_or - code_quality.rs: collapsible if, map_or → is_none_or - commit.rs: collapsible match guard - explore.rs: needless_range_loop → iterator enumerate - skills.rs: map_or(false,...) → is_some_and - semantic_search.rs: map_or → is_none_or, sort_by → sort_by_key, remove explicit type to avoid type_complexity CI was failing with 'error: could not compile zesdex-infrastructure due to 18 previous errors' at clippy step. --- .../src/best_practice/arch_audit.rs | 6 +-- .../src/best_practice/code_quality.rs | 50 +++++++++---------- .../src/best_practice/commit.rs | 12 ++--- .../src/best_practice/explore.rs | 8 +-- .../src/best_practice/skills.rs | 2 +- apps/infrastructure/src/lib.rs | 4 +- .../src/tools/semantic_search.rs | 16 +++--- 7 files changed, 48 insertions(+), 50 deletions(-) diff --git a/apps/infrastructure/src/best_practice/arch_audit.rs b/apps/infrastructure/src/best_practice/arch_audit.rs index 90296be..cd43418 100644 --- a/apps/infrastructure/src/best_practice/arch_audit.rs +++ b/apps/infrastructure/src/best_practice/arch_audit.rs @@ -181,7 +181,7 @@ fn scan_file( if trimmed.starts_with("use ") { for &forbidden in forbidden { let pattern = format!("use {forbidden}"); - if trimmed.starts_with(&pattern) || trimmed.starts_with(&format!("use crate::")) { + if trimmed.starts_with(&pattern) || trimmed.starts_with("use crate::") { // `use crate::` in domain could reference domain-only items — skip. continue; } @@ -234,11 +234,11 @@ pub fn audit_layering(root: &Path) -> Result { let mut files_scanned = 0; for entry in Walk::new(&apps_dir).flatten() { - if entry.file_type().map_or(true, |ft| !ft.is_file()) { + if entry.file_type().is_none_or(|ft| !ft.is_file()) { continue; } let path = entry.path(); - if path.extension().map_or(true, |e| e != "rs") { + if path.extension().is_none_or(|e| e != "rs") { continue; } diff --git a/apps/infrastructure/src/best_practice/code_quality.rs b/apps/infrastructure/src/best_practice/code_quality.rs index 9d2f8ea..cc33653 100644 --- a/apps/infrastructure/src/best_practice/code_quality.rs +++ b/apps/infrastructure/src/best_practice/code_quality.rs @@ -146,29 +146,29 @@ pub fn scan_quality_file(file_path: &Path, root: &Path) -> Vec { } // ── Rule: Missing doc comments on pub items ──────────────────── - if trimmed.starts_with("pub ") || trimmed.starts_with("pub(") { - if !prev_line_doc && !prev_line_empty { - // Check it's a struct/enum/fn/trait/type/const/mod - let is_item = trimmed.starts_with("pub fn ") - || trimmed.starts_with("pub struct ") - || trimmed.starts_with("pub enum ") - || trimmed.starts_with("pub trait ") - || trimmed.starts_with("pub type ") - || trimmed.starts_with("pub const ") - || trimmed.starts_with("pub mod ") - || trimmed.starts_with("pub(crate) fn ") - || trimmed.starts_with("pub(crate) struct ") - || trimmed.starts_with("pub(crate) enum ") - || trimmed.starts_with("pub(crate) trait "); - if is_item { - findings.push(Finding { - severity: super::arch_audit::Severity::Info, - rule: "missing-doc", - file: relative.clone(), - line: line_num, - message: format!("Missing doc comment on pub item: {trimmed}"), - }); - } + if (trimmed.starts_with("pub ") || trimmed.starts_with("pub(")) + && !prev_line_doc && !prev_line_empty + { + // Check it's a struct/enum/fn/trait/type/const/mod + let is_item = trimmed.starts_with("pub fn ") + || trimmed.starts_with("pub struct ") + || trimmed.starts_with("pub enum ") + || trimmed.starts_with("pub trait ") + || trimmed.starts_with("pub type ") + || trimmed.starts_with("pub const ") + || trimmed.starts_with("pub mod ") + || trimmed.starts_with("pub(crate) fn ") + || trimmed.starts_with("pub(crate) struct ") + || trimmed.starts_with("pub(crate) enum ") + || trimmed.starts_with("pub(crate) trait "); + if is_item { + findings.push(Finding { + severity: super::arch_audit::Severity::Info, + rule: "missing-doc", + file: relative.clone(), + line: line_num, + message: format!("Missing doc comment on pub item: {trimmed}"), + }); } } @@ -217,11 +217,11 @@ pub fn scan_quality(root: &Path) -> Result { let mut files_scanned = 0; for entry in Walk::new(&apps_dir).flatten() { - if entry.file_type().map_or(true, |ft| !ft.is_file()) { + if entry.file_type().is_none_or(|ft| !ft.is_file()) { continue; } let path = entry.path(); - if path.extension().map_or(true, |e| e != "rs") { + if path.extension().is_none_or(|e| e != "rs") { continue; } files_scanned += 1; diff --git a/apps/infrastructure/src/best_practice/commit.rs b/apps/infrastructure/src/best_practice/commit.rs index f076c14..cf90900 100644 --- a/apps/infrastructure/src/best_practice/commit.rs +++ b/apps/infrastructure/src/best_practice/commit.rs @@ -108,13 +108,11 @@ pub fn validate_commit_message(msg: &str) -> Result<(), Vec> { // Type-specific rules. match type_ { "chore" | "docs" | "refactor" | "test" | "style" | "perf" | "ci" | "build" - | "revert" => { - if scope.is_some() { - errors.push(format!( - "'{type_}' commits should not use a scope. \ - Only 'feat' and 'fix' require scopes." - )); - } + | "revert" if scope.is_some() => { + errors.push(format!( + "'{type_}' commits should not use a scope. \ + Only 'feat' and 'fix' require scopes." + )); } _ => {} } diff --git a/apps/infrastructure/src/best_practice/explore.rs b/apps/infrastructure/src/best_practice/explore.rs index 2ddabea..c9888d5 100644 --- a/apps/infrastructure/src/best_practice/explore.rs +++ b/apps/infrastructure/src/best_practice/explore.rs @@ -196,14 +196,14 @@ async fn run_explore_phase( turn_events: &Arc>>, ) -> Result { // ── 1. Emit Pending for all agents (appears instantly in workflow tab) ─ - for i in 0..EXPLORE_AGENT_COUNT { - emit_pending(turn_events, EXPLORE_IDS[i], EXPLORE_LABELS[i]); + for (i, &id) in EXPLORE_IDS.iter().enumerate() { + emit_pending(turn_events, id, EXPLORE_LABELS[i]); } // ── 2. Prepare directives ─────────────────────────────────────────── let mut directives: Vec = Vec::with_capacity(EXPLORE_AGENT_COUNT); - for i in 0..EXPLORE_AGENT_COUNT { - let mut d = EXPLORE_DIRECTIVES[i].to_string(); + for (i, &d) in EXPLORE_DIRECTIVES.iter().enumerate() { + let mut d = d.to_string(); if i == 2 { d.push_str(&format!("\n\nThe user's current query is: \"{query}\"")); } diff --git a/apps/infrastructure/src/best_practice/skills.rs b/apps/infrastructure/src/best_practice/skills.rs index 061718c..dc4a41b 100644 --- a/apps/infrastructure/src/best_practice/skills.rs +++ b/apps/infrastructure/src/best_practice/skills.rs @@ -35,7 +35,7 @@ impl EmbeddedSkills { match entry { DirEntry::Dir(sub) => walk(sub, skills), DirEntry::File(file) => { - if file.path().file_name().map_or(false, |n| n == "SKILL.md") { + if file.path().file_name().is_some_and(|n| n == "SKILL.md") { if let Some(parent) = file .path() .parent() diff --git a/apps/infrastructure/src/lib.rs b/apps/infrastructure/src/lib.rs index 6a518d5..4f85cbe 100644 --- a/apps/infrastructure/src/lib.rs +++ b/apps/infrastructure/src/lib.rs @@ -54,8 +54,8 @@ pub use zesdex_domain::*; use std::path::PathBuf; use std::sync::Arc; -/// Which kind of caller (main agent vs. subagent vs. reviewer) is -/// invoking a tool, used to scope permissions and tag log/output paths. +// Which kind of caller (main agent vs. subagent vs. reviewer) is +// invoking a tool, used to scope permissions and tag log/output paths. // --------------------------------------------------------------------------- // TurnEvent & runtime types have been moved to zesdex_domain::agent // --------------------------------------------------------------------------- diff --git a/apps/infrastructure/src/tools/semantic_search.rs b/apps/infrastructure/src/tools/semantic_search.rs index 04d2134..b2a9b7e 100644 --- a/apps/infrastructure/src/tools/semantic_search.rs +++ b/apps/infrastructure/src/tools/semantic_search.rs @@ -286,7 +286,7 @@ impl SymbolIndex { let walker = ignore::Walk::new(path); // Pre-compile per-extension dispatch table. - let ext_dispatch: HashMap<&str, fn(&str, &str) -> Vec> = HashMap::from([ + let ext_dispatch = HashMap::from([ ("rs", extract_rust as fn(&str, &str) -> Vec), ("ts", extract_typescript as fn(&str, &str) -> Vec), ("tsx", extract_typescript as fn(&str, &str) -> Vec), @@ -385,9 +385,9 @@ impl SymbolIndex { .symbols .iter() .filter(|s| { - language_filter.as_ref().map_or(true, |l| s.language == *l) - && kind_filter.as_ref().map_or(true, |k| s.kind == *k) - && file_filter.map_or(true, |f| s.file.contains(f)) + language_filter.as_ref().is_none_or(|l| s.language == *l) + && kind_filter.as_ref().is_none_or(|k| s.kind == *k) + && file_filter.is_none_or(|f| s.file.contains(f)) }) .take(max_results) .collect(); @@ -401,7 +401,7 @@ impl SymbolIndex { *counts.entry(sym.language.clone()).or_default() += 1; } let mut sorted: Vec<(Language, usize)> = counts.into_iter().collect(); - sorted.sort_by(|a, b| b.1.cmp(&a.1)); + sorted.sort_by_key(|b| std::cmp::Reverse(b.1)); sorted } @@ -412,7 +412,7 @@ impl SymbolIndex { *counts.entry(sym.kind.clone()).or_default() += 1; } let mut sorted: Vec<(SymbolKind, usize)> = counts.into_iter().collect(); - sorted.sort_by(|a, b| b.1.cmp(&a.1)); + sorted.sort_by_key(|b| std::cmp::Reverse(b.1)); sorted } } @@ -1299,8 +1299,8 @@ impl Tool for SemanticSearch { let filtered: Vec<&&CodeSymbol> = results .iter() - .filter(|s| target_kind.as_ref().map_or(true, |k| s.kind == *k)) - .filter(|s| target_lang.as_ref().map_or(true, |l| s.language == *l)) + .filter(|s| target_kind.as_ref().is_none_or(|k| s.kind == *k)) + .filter(|s| target_lang.as_ref().is_none_or(|l| s.language == *l)) .take(max_results) .collect();