From ea2a9e8a1d43e597dd121e687980a2e5414d5676 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Fri, 6 Mar 2026 22:43:44 +0100 Subject: [PATCH] Fix clippy warnings and fmt issues to pass CI Replace expect/unwrap calls with safe alternatives, add Default impls for parser structs and Toasts, fix redundant closures, collapse nested ifs, remove unused import, and allow recursive-only-self/too-many-args lints in compliance-graph. Co-Authored-By: Claude Opus 4.6 --- compliance-agent/src/api/handlers/mod.rs | 8 ++------ compliance-core/src/models/dast.rs | 1 + compliance-dashboard/src/components/toast.rs | 6 ++++++ .../src/infrastructure/repositories.rs | 5 +---- compliance-dashboard/src/pages/chat_index.rs | 1 - .../src/pages/dast_findings.rs | 2 +- .../src/pages/graph_explorer.rs | 12 ++++++------ compliance-dast/src/crawler/mod.rs | 18 ++++++++++++------ compliance-dast/src/recon/mod.rs | 8 ++++---- compliance-graph/src/graph/community.rs | 11 +++++------ compliance-graph/src/graph/embedding_store.rs | 14 ++++++-------- compliance-graph/src/graph/engine.rs | 4 ++-- compliance-graph/src/lib.rs | 3 +++ compliance-graph/src/parsers/javascript.rs | 6 ++++++ compliance-graph/src/parsers/python.rs | 6 ++++++ compliance-graph/src/parsers/rust_parser.rs | 6 ++++++ compliance-graph/src/parsers/typescript.rs | 6 ++++++ 17 files changed, 73 insertions(+), 44 deletions(-) diff --git a/compliance-agent/src/api/handlers/mod.rs b/compliance-agent/src/api/handlers/mod.rs index 188684b..a3b7909 100644 --- a/compliance-agent/src/api/handlers/mod.rs +++ b/compliance-agent/src/api/handlers/mod.rs @@ -307,8 +307,7 @@ pub async fn delete_repository( Extension(agent): AgentExt, Path(id): Path, ) -> Result, StatusCode> { - let oid = - mongodb::bson::oid::ObjectId::parse_str(&id).map_err(|_| StatusCode::BAD_REQUEST)?; + let oid = mongodb::bson::oid::ObjectId::parse_str(&id).map_err(|_| StatusCode::BAD_REQUEST)?; let db = &agent.db; // Delete the repository @@ -333,10 +332,7 @@ pub async fn delete_repository( .await; let _ = db.graph_nodes().delete_many(doc! { "repo_id": &id }).await; let _ = db.graph_edges().delete_many(doc! { "repo_id": &id }).await; - let _ = db - .graph_builds() - .delete_many(doc! { "repo_id": &id }) - .await; + let _ = db.graph_builds().delete_many(doc! { "repo_id": &id }).await; let _ = db .impact_analyses() .delete_many(doc! { "repo_id": &id }) diff --git a/compliance-core/src/models/dast.rs b/compliance-core/src/models/dast.rs index 521e513..d2755a0 100644 --- a/compliance-core/src/models/dast.rs +++ b/compliance-core/src/models/dast.rs @@ -244,6 +244,7 @@ pub struct DastFinding { } impl DastFinding { + #[allow(clippy::too_many_arguments)] pub fn new( scan_run_id: String, target_id: String, diff --git a/compliance-dashboard/src/components/toast.rs b/compliance-dashboard/src/components/toast.rs index 13a8f98..dec6d96 100644 --- a/compliance-dashboard/src/components/toast.rs +++ b/compliance-dashboard/src/components/toast.rs @@ -20,6 +20,12 @@ pub struct Toasts { next_id: Signal, } +impl Default for Toasts { + fn default() -> Self { + Self::new() + } +} + impl Toasts { pub fn new() -> Self { Self { diff --git a/compliance-dashboard/src/infrastructure/repositories.rs b/compliance-dashboard/src/infrastructure/repositories.rs index 942a865..f4f740d 100644 --- a/compliance-dashboard/src/infrastructure/repositories.rs +++ b/compliance-dashboard/src/infrastructure/repositories.rs @@ -65,10 +65,7 @@ pub async fn add_repository( pub async fn delete_repository(repo_id: String) -> Result<(), ServerFnError> { let state: super::server_state::ServerState = dioxus_fullstack::FullstackContext::extract().await?; - let url = format!( - "{}/api/v1/repositories/{repo_id}", - state.agent_api_url - ); + let url = format!("{}/api/v1/repositories/{repo_id}", state.agent_api_url); let client = reqwest::Client::new(); let resp = client diff --git a/compliance-dashboard/src/pages/chat_index.rs b/compliance-dashboard/src/pages/chat_index.rs index 73ff29a..5d56141 100644 --- a/compliance-dashboard/src/pages/chat_index.rs +++ b/compliance-dashboard/src/pages/chat_index.rs @@ -2,7 +2,6 @@ use dioxus::prelude::*; use crate::app::Route; use crate::components::page_header::PageHeader; -use crate::infrastructure::chat::fetch_embedding_status; use crate::infrastructure::repositories::fetch_repositories; #[component] diff --git a/compliance-dashboard/src/pages/dast_findings.rs b/compliance-dashboard/src/pages/dast_findings.rs index 1729c60..9c5b43e 100644 --- a/compliance-dashboard/src/pages/dast_findings.rs +++ b/compliance-dashboard/src/pages/dast_findings.rs @@ -49,7 +49,7 @@ pub fn DastFindingsPage() -> Element { } td { Link { - to: Route::DastFindingDetailPage { id: id }, + to: Route::DastFindingDetailPage { id }, "{finding.get(\"title\").and_then(|v| v.as_str()).unwrap_or(\"-\")}" } } diff --git a/compliance-dashboard/src/pages/graph_explorer.rs b/compliance-dashboard/src/pages/graph_explorer.rs index ce5b400..93c14d3 100644 --- a/compliance-dashboard/src/pages/graph_explorer.rs +++ b/compliance-dashboard/src/pages/graph_explorer.rs @@ -27,13 +27,13 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { let mut inspector_open = use_signal(|| false); // Search state - let mut search_query = use_signal(|| String::new()); - let mut search_results = use_signal(|| Vec::::new()); - let mut file_filter = use_signal(|| String::new()); + let mut search_query = use_signal(String::new); + let mut search_results = use_signal(Vec::::new); + let mut file_filter = use_signal(String::new); // Store serialized graph JSON in signals so use_effect can react to them - let mut nodes_json = use_signal(|| String::new()); - let mut edges_json = use_signal(|| String::new()); + let mut nodes_json = use_signal(String::new); + let mut edges_json = use_signal(String::new); let mut graph_ready = use_signal(|| false); // When resource resolves, serialize the data into signals @@ -404,7 +404,7 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { } else if node_count > 0 { // Data exists but nodes array was empty (shouldn't happen) div { class: "loading", "Loading graph visualization..." } - } else if matches!(&*graph_data.read(), None) { + } else if (*graph_data.read()).is_none() { div { class: "loading", "Loading graph data..." } } else { div { class: "graph-empty-state", diff --git a/compliance-dast/src/crawler/mod.rs b/compliance-dast/src/crawler/mod.rs index 7bcf433..6b7c087 100644 --- a/compliance-dast/src/crawler/mod.rs +++ b/compliance-dast/src/crawler/mod.rs @@ -95,8 +95,10 @@ impl WebCrawler { let document = Html::parse_document(&body); // Extract links - let link_selector = Selector::parse("a[href]") - .unwrap_or_else(|_| Selector::parse("a").expect("valid selector")); + let link_selector = match Selector::parse("a[href]") { + Ok(s) => s, + Err(_) => continue, + }; for element in document.select(&link_selector) { if let Some(href) = element.value().attr("href") { if let Some(absolute_url) = self.resolve_url(&base, &url, href) { @@ -110,10 +112,14 @@ impl WebCrawler { } // Extract forms - let form_selector = Selector::parse("form") - .unwrap_or_else(|_| Selector::parse("form").expect("valid selector")); - let input_selector = Selector::parse("input, select, textarea") - .unwrap_or_else(|_| Selector::parse("input").expect("valid selector")); + let form_selector = match Selector::parse("form") { + Ok(s) => s, + Err(_) => continue, + }; + let input_selector = match Selector::parse("input, select, textarea") { + Ok(s) => s, + Err(_) => continue, + }; for form in document.select(&form_selector) { let action = form.value().attr("action").unwrap_or(""); diff --git a/compliance-dast/src/recon/mod.rs b/compliance-dast/src/recon/mod.rs index a08db6a..46d27e8 100644 --- a/compliance-dast/src/recon/mod.rs +++ b/compliance-dast/src/recon/mod.rs @@ -121,10 +121,10 @@ impl ReconAgent { let body_lower = body.to_lowercase(); for (tech, pattern) in &patterns { - if body_lower.contains(&pattern.to_lowercase()) { - if !result.technologies.contains(&tech.to_string()) { - result.technologies.push(tech.to_string()); - } + if body_lower.contains(&pattern.to_lowercase()) + && !result.technologies.contains(&tech.to_string()) + { + result.technologies.push(tech.to_string()); } } } diff --git a/compliance-graph/src/graph/community.rs b/compliance-graph/src/graph/community.rs index b24d254..799d140 100644 --- a/compliance-graph/src/graph/community.rs +++ b/compliance-graph/src/graph/community.rs @@ -109,8 +109,8 @@ pub fn detect_communities(code_graph: &CodeGraph) -> u32 { let mut comm_remap: HashMap = HashMap::new(); let mut next_id: u32 = 0; for &c in community.values() { - if !comm_remap.contains_key(&c) { - comm_remap.insert(c, next_id); + if let std::collections::hash_map::Entry::Vacant(e) = comm_remap.entry(c) { + e.insert(next_id); next_id += 1; } } @@ -137,8 +137,7 @@ pub fn detect_communities(code_graph: &CodeGraph) -> u32 { /// Apply community assignments back to code nodes pub fn apply_communities(code_graph: &mut CodeGraph) -> u32 { - let count = detect_communities_with_assignment(code_graph); - count + detect_communities_with_assignment(code_graph) } /// Detect communities and write assignments into the nodes @@ -235,8 +234,8 @@ fn detect_communities_with_assignment(code_graph: &mut CodeGraph) -> u32 { let mut comm_remap: HashMap = HashMap::new(); let mut next_id: u32 = 0; for &c in community.values() { - if !comm_remap.contains_key(&c) { - comm_remap.insert(c, next_id); + if let std::collections::hash_map::Entry::Vacant(e) = comm_remap.entry(c) { + e.insert(next_id); next_id += 1; } } diff --git a/compliance-graph/src/graph/embedding_store.rs b/compliance-graph/src/graph/embedding_store.rs index 689d8af..888cd81 100644 --- a/compliance-graph/src/graph/embedding_store.rs +++ b/compliance-graph/src/graph/embedding_store.rs @@ -96,17 +96,15 @@ impl EmbeddingStore { }; if status == EmbeddingBuildStatus::Completed || status == EmbeddingBuildStatus::Failed { - update - .get_document_mut("$set") - .unwrap() - .insert("completed_at", mongodb::bson::DateTime::now()); + if let Ok(set_doc) = update.get_document_mut("$set") { + set_doc.insert("completed_at", mongodb::bson::DateTime::now()); + } } if let Some(msg) = error_message { - update - .get_document_mut("$set") - .unwrap() - .insert("error_message", msg); + if let Ok(set_doc) = update.get_document_mut("$set") { + set_doc.insert("error_message", msg); + } } self.builds diff --git a/compliance-graph/src/graph/engine.rs b/compliance-graph/src/graph/engine.rs index b11af7f..5ec71c3 100644 --- a/compliance-graph/src/graph/engine.rs +++ b/compliance-graph/src/graph/engine.rs @@ -133,10 +133,10 @@ impl GraphEngine { } /// Try to resolve an edge target to a known node - fn resolve_edge_target<'a>( + fn resolve_edge_target( &self, target: &str, - node_map: &'a HashMap, + node_map: &HashMap, ) -> Option { // Direct match if let Some(idx) = node_map.get(target) { diff --git a/compliance-graph/src/lib.rs b/compliance-graph/src/lib.rs index 8945bb7..bceea55 100644 --- a/compliance-graph/src/lib.rs +++ b/compliance-graph/src/lib.rs @@ -1,3 +1,6 @@ +#![allow(clippy::only_used_in_recursion)] +#![allow(clippy::too_many_arguments)] + pub mod graph; pub mod parsers; pub mod search; diff --git a/compliance-graph/src/parsers/javascript.rs b/compliance-graph/src/parsers/javascript.rs index 0dae26e..e8637e8 100644 --- a/compliance-graph/src/parsers/javascript.rs +++ b/compliance-graph/src/parsers/javascript.rs @@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser}; pub struct JavaScriptParser; +impl Default for JavaScriptParser { + fn default() -> Self { + Self::new() + } +} + impl JavaScriptParser { pub fn new() -> Self { Self diff --git a/compliance-graph/src/parsers/python.rs b/compliance-graph/src/parsers/python.rs index bc0af2f..d11c80a 100644 --- a/compliance-graph/src/parsers/python.rs +++ b/compliance-graph/src/parsers/python.rs @@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser}; pub struct PythonParser; +impl Default for PythonParser { + fn default() -> Self { + Self::new() + } +} + impl PythonParser { pub fn new() -> Self { Self diff --git a/compliance-graph/src/parsers/rust_parser.rs b/compliance-graph/src/parsers/rust_parser.rs index f05c5c5..391a7d4 100644 --- a/compliance-graph/src/parsers/rust_parser.rs +++ b/compliance-graph/src/parsers/rust_parser.rs @@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser}; pub struct RustParser; +impl Default for RustParser { + fn default() -> Self { + Self::new() + } +} + impl RustParser { pub fn new() -> Self { Self diff --git a/compliance-graph/src/parsers/typescript.rs b/compliance-graph/src/parsers/typescript.rs index 8f3f15a..183b451 100644 --- a/compliance-graph/src/parsers/typescript.rs +++ b/compliance-graph/src/parsers/typescript.rs @@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser}; pub struct TypeScriptParser; +impl Default for TypeScriptParser { + fn default() -> Self { + Self::new() + } +} + impl TypeScriptParser { pub fn new() -> Self { Self