fix(rust): resolve all clippy warnings treated as errors in CI

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.
This commit is contained in:
Cyrene (Mem)
2026-07-22 14:16:56 +07:00
parent 958645ed7f
commit 6b90c7eb0d
7 changed files with 48 additions and 50 deletions
@@ -181,7 +181,7 @@ fn scan_file(
if trimmed.starts_with("use ") { if trimmed.starts_with("use ") {
for &forbidden in forbidden { for &forbidden in forbidden {
let pattern = format!("use {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. // `use crate::` in domain could reference domain-only items — skip.
continue; continue;
} }
@@ -234,11 +234,11 @@ pub fn audit_layering(root: &Path) -> Result<AuditReport> {
let mut files_scanned = 0; let mut files_scanned = 0;
for entry in Walk::new(&apps_dir).flatten() { 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; continue;
} }
let path = entry.path(); let path = entry.path();
if path.extension().map_or(true, |e| e != "rs") { if path.extension().is_none_or(|e| e != "rs") {
continue; continue;
} }
@@ -146,29 +146,29 @@ pub fn scan_quality_file(file_path: &Path, root: &Path) -> Vec<Finding> {
} }
// ── Rule: Missing doc comments on pub items ──────────────────── // ── Rule: Missing doc comments on pub items ────────────────────
if trimmed.starts_with("pub ") || trimmed.starts_with("pub(") { if (trimmed.starts_with("pub ") || trimmed.starts_with("pub("))
if !prev_line_doc && !prev_line_empty { && !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 ") // Check it's a struct/enum/fn/trait/type/const/mod
|| trimmed.starts_with("pub struct ") let is_item = trimmed.starts_with("pub fn ")
|| trimmed.starts_with("pub enum ") || trimmed.starts_with("pub struct ")
|| trimmed.starts_with("pub trait ") || trimmed.starts_with("pub enum ")
|| trimmed.starts_with("pub type ") || trimmed.starts_with("pub trait ")
|| trimmed.starts_with("pub const ") || trimmed.starts_with("pub type ")
|| trimmed.starts_with("pub mod ") || trimmed.starts_with("pub const ")
|| trimmed.starts_with("pub(crate) fn ") || trimmed.starts_with("pub mod ")
|| trimmed.starts_with("pub(crate) struct ") || trimmed.starts_with("pub(crate) fn ")
|| trimmed.starts_with("pub(crate) enum ") || trimmed.starts_with("pub(crate) struct ")
|| trimmed.starts_with("pub(crate) trait "); || trimmed.starts_with("pub(crate) enum ")
if is_item { || trimmed.starts_with("pub(crate) trait ");
findings.push(Finding { if is_item {
severity: super::arch_audit::Severity::Info, findings.push(Finding {
rule: "missing-doc", severity: super::arch_audit::Severity::Info,
file: relative.clone(), rule: "missing-doc",
line: line_num, file: relative.clone(),
message: format!("Missing doc comment on pub item: {trimmed}"), line: line_num,
}); message: format!("Missing doc comment on pub item: {trimmed}"),
} });
} }
} }
@@ -217,11 +217,11 @@ pub fn scan_quality(root: &Path) -> Result<CodeQualityReport> {
let mut files_scanned = 0; let mut files_scanned = 0;
for entry in Walk::new(&apps_dir).flatten() { 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; continue;
} }
let path = entry.path(); let path = entry.path();
if path.extension().map_or(true, |e| e != "rs") { if path.extension().is_none_or(|e| e != "rs") {
continue; continue;
} }
files_scanned += 1; files_scanned += 1;
@@ -108,13 +108,11 @@ pub fn validate_commit_message(msg: &str) -> Result<(), Vec<String>> {
// Type-specific rules. // Type-specific rules.
match type_ { match type_ {
"chore" | "docs" | "refactor" | "test" | "style" | "perf" | "ci" | "build" "chore" | "docs" | "refactor" | "test" | "style" | "perf" | "ci" | "build"
| "revert" => { | "revert" if scope.is_some() => {
if scope.is_some() { errors.push(format!(
errors.push(format!( "'{type_}' commits should not use a scope. \
"'{type_}' commits should not use a scope. \ Only 'feat' and 'fix' require scopes."
Only 'feat' and 'fix' require scopes." ));
));
}
} }
_ => {} _ => {}
} }
@@ -196,14 +196,14 @@ async fn run_explore_phase(
turn_events: &Arc<Mutex<VecDeque<TurnEvent>>>, turn_events: &Arc<Mutex<VecDeque<TurnEvent>>>,
) -> Result<String> { ) -> Result<String> {
// ── 1. Emit Pending for all agents (appears instantly in workflow tab) ─ // ── 1. Emit Pending for all agents (appears instantly in workflow tab) ─
for i in 0..EXPLORE_AGENT_COUNT { for (i, &id) in EXPLORE_IDS.iter().enumerate() {
emit_pending(turn_events, EXPLORE_IDS[i], EXPLORE_LABELS[i]); emit_pending(turn_events, id, EXPLORE_LABELS[i]);
} }
// ── 2. Prepare directives ─────────────────────────────────────────── // ── 2. Prepare directives ───────────────────────────────────────────
let mut directives: Vec<String> = Vec::with_capacity(EXPLORE_AGENT_COUNT); let mut directives: Vec<String> = Vec::with_capacity(EXPLORE_AGENT_COUNT);
for i in 0..EXPLORE_AGENT_COUNT { for (i, &d) in EXPLORE_DIRECTIVES.iter().enumerate() {
let mut d = EXPLORE_DIRECTIVES[i].to_string(); let mut d = d.to_string();
if i == 2 { if i == 2 {
d.push_str(&format!("\n\nThe user's current query is: \"{query}\"")); d.push_str(&format!("\n\nThe user's current query is: \"{query}\""));
} }
@@ -35,7 +35,7 @@ impl EmbeddedSkills {
match entry { match entry {
DirEntry::Dir(sub) => walk(sub, skills), DirEntry::Dir(sub) => walk(sub, skills),
DirEntry::File(file) => { 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 if let Some(parent) = file
.path() .path()
.parent() .parent()
+2 -2
View File
@@ -54,8 +54,8 @@ pub use zesdex_domain::*;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
/// Which kind of caller (main agent vs. subagent vs. reviewer) is // Which kind of caller (main agent vs. subagent vs. reviewer) is
/// invoking a tool, used to scope permissions and tag log/output paths. // invoking a tool, used to scope permissions and tag log/output paths.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// TurnEvent & runtime types have been moved to zesdex_domain::agent // TurnEvent & runtime types have been moved to zesdex_domain::agent
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -286,7 +286,7 @@ impl SymbolIndex {
let walker = ignore::Walk::new(path); let walker = ignore::Walk::new(path);
// Pre-compile per-extension dispatch table. // Pre-compile per-extension dispatch table.
let ext_dispatch: HashMap<&str, fn(&str, &str) -> Vec<CodeSymbol>> = HashMap::from([ let ext_dispatch = HashMap::from([
("rs", extract_rust as fn(&str, &str) -> Vec<CodeSymbol>), ("rs", extract_rust as fn(&str, &str) -> Vec<CodeSymbol>),
("ts", extract_typescript as fn(&str, &str) -> Vec<CodeSymbol>), ("ts", extract_typescript as fn(&str, &str) -> Vec<CodeSymbol>),
("tsx", extract_typescript as fn(&str, &str) -> Vec<CodeSymbol>), ("tsx", extract_typescript as fn(&str, &str) -> Vec<CodeSymbol>),
@@ -385,9 +385,9 @@ impl SymbolIndex {
.symbols .symbols
.iter() .iter()
.filter(|s| { .filter(|s| {
language_filter.as_ref().map_or(true, |l| s.language == *l) language_filter.as_ref().is_none_or(|l| s.language == *l)
&& kind_filter.as_ref().map_or(true, |k| s.kind == *k) && kind_filter.as_ref().is_none_or(|k| s.kind == *k)
&& file_filter.map_or(true, |f| s.file.contains(f)) && file_filter.is_none_or(|f| s.file.contains(f))
}) })
.take(max_results) .take(max_results)
.collect(); .collect();
@@ -401,7 +401,7 @@ impl SymbolIndex {
*counts.entry(sym.language.clone()).or_default() += 1; *counts.entry(sym.language.clone()).or_default() += 1;
} }
let mut sorted: Vec<(Language, usize)> = counts.into_iter().collect(); 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 sorted
} }
@@ -412,7 +412,7 @@ impl SymbolIndex {
*counts.entry(sym.kind.clone()).or_default() += 1; *counts.entry(sym.kind.clone()).or_default() += 1;
} }
let mut sorted: Vec<(SymbolKind, usize)> = counts.into_iter().collect(); 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 sorted
} }
} }
@@ -1299,8 +1299,8 @@ impl Tool for SemanticSearch {
let filtered: Vec<&&CodeSymbol> = results let filtered: Vec<&&CodeSymbol> = results
.iter() .iter()
.filter(|s| target_kind.as_ref().map_or(true, |k| s.kind == *k)) .filter(|s| target_kind.as_ref().is_none_or(|k| s.kind == *k))
.filter(|s| target_lang.as_ref().map_or(true, |l| s.language == *l)) .filter(|s| target_lang.as_ref().is_none_or(|l| s.language == *l))
.take(max_results) .take(max_results)
.collect(); .collect();