From 7cd867c650b0891ecfeb10cb10b04aeec314b277 Mon Sep 17 00:00:00 2001 From: oabrivard Date: Wed, 25 Mar 2026 09:52:08 +0100 Subject: [PATCH] fix: resolve all clippy warnings Co-Authored-By: Claude Sonnet 4.6 --- backend/src/db/llm_call_log.rs | 1 + backend/src/handlers/auth.rs | 1 + backend/src/services/llm/anthropic.rs | 8 ++++---- backend/src/services/rate_limiter.rs | 6 ++++++ backend/src/services/scraper.rs | 6 +----- backend/src/services/source_scraper.rs | 1 + backend/src/services/synthesis.rs | 20 +++++++++++--------- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/backend/src/db/llm_call_log.rs b/backend/src/db/llm_call_log.rs index 849baee..c0bf81e 100644 --- a/backend/src/db/llm_call_log.rs +++ b/backend/src/db/llm_call_log.rs @@ -21,6 +21,7 @@ pub struct LlmCallLogRow { } /// Insert a single LLM call log entry. +#[allow(clippy::too_many_arguments)] pub async fn insert( pool: &PgPool, user_id: Uuid, diff --git a/backend/src/handlers/auth.rs b/backend/src/handlers/auth.rs index 8d395de..5849755 100644 --- a/backend/src/handlers/auth.rs +++ b/backend/src/handlers/auth.rs @@ -60,6 +60,7 @@ const GENERIC_AUTH_MESSAGE: &str = /// Validates the Turnstile token, checks if the user already exists: /// - If the user exists, sends a magic link (same as login). /// - If not, creates the user and sends a magic link. +/// /// Always returns the same response to prevent email enumeration. pub async fn register( State(state): State, diff --git a/backend/src/services/llm/anthropic.rs b/backend/src/services/llm/anthropic.rs index 7ddc532..48e3ffc 100644 --- a/backend/src/services/llm/anthropic.rs +++ b/backend/src/services/llm/anthropic.rs @@ -169,10 +169,10 @@ fn strip_code_fences(text: &str) -> &str { let trimmed = text.trim(); // Check for ```json or ``` prefix - let without_prefix = if trimmed.starts_with("```json") { - &trimmed[7..] - } else if trimmed.starts_with("```") { - &trimmed[3..] + let without_prefix = if let Some(stripped) = trimmed.strip_prefix("```json") { + stripped + } else if let Some(stripped) = trimmed.strip_prefix("```") { + stripped } else { return trimmed; }; diff --git a/backend/src/services/rate_limiter.rs b/backend/src/services/rate_limiter.rs index acb5571..a035f33 100644 --- a/backend/src/services/rate_limiter.rs +++ b/backend/src/services/rate_limiter.rs @@ -146,6 +146,12 @@ struct ProviderRateLimiterInner { const DEFAULT_MAX_REQUESTS: u32 = 29; const DEFAULT_TIME_WINDOW_SECS: u64 = 60; +impl Default for ProviderRateLimiter { + fn default() -> Self { + Self::new() + } +} + impl ProviderRateLimiter { /// Create a new provider rate limiter with empty buckets. /// diff --git a/backend/src/services/scraper.rs b/backend/src/services/scraper.rs index d63e40a..9e61aa2 100644 --- a/backend/src/services/scraper.rs +++ b/backend/src/services/scraper.rs @@ -449,11 +449,7 @@ fn detect_short_page_error(body_text: &str) -> bool { for (idx, _) in lower.match_indices("404") { for kw in &proximity_keywords { if let Some(kw_idx) = lower.find(kw) { - let distance = if idx > kw_idx { - idx - kw_idx - } else { - kw_idx - idx - }; + let distance = idx.abs_diff(kw_idx); if distance <= 50 { return true; } diff --git a/backend/src/services/source_scraper.rs b/backend/src/services/source_scraper.rs index 7a5cc9c..a8e19fa 100644 --- a/backend/src/services/source_scraper.rs +++ b/backend/src/services/source_scraper.rs @@ -126,6 +126,7 @@ pub fn extract_body_html(html: &str) -> String { /// Extract article links using LLM analysis of the page HTML. /// /// Falls back to heuristic extraction if the LLM call fails or returns empty. +#[allow(clippy::too_many_arguments)] pub async fn extract_article_links_with_llm( http_client: &reqwest::Client, source_url: &str, diff --git a/backend/src/services/synthesis.rs b/backend/src/services/synthesis.rs index 6f5b6ca..6f3422c 100644 --- a/backend/src/services/synthesis.rs +++ b/backend/src/services/synthesis.rs @@ -87,6 +87,12 @@ pub struct JobStore { /// Jobs expire after 1 hour (allows SSE reconnection). const JOB_TTL: Duration = Duration::from_secs(3600); +impl Default for JobStore { + fn default() -> Self { + Self::new() + } +} + impl JobStore { /// Create a new empty job store. pub fn new() -> Self { @@ -593,7 +599,7 @@ async fn run_generation_inner( // History dedup if settings.article_history_days > 0 { let hash = hash_article_url(&item.url); - let exists = db::article_history::check_urls_exist(&state.pool, user_id, &[hash.clone()]).await.unwrap_or_default(); + let exists = db::article_history::check_urls_exist(&state.pool, user_id, std::slice::from_ref(&hash)).await.unwrap_or_default(); if exists.contains(&hash) { trace_article(&state.pool, user_id, job_id, &item.url, &item.title, "web_search", None, None, None, "filtered_history", false).await; continue; @@ -711,6 +717,7 @@ fn emit_progress(tx: &watch::Sender, step: &str, message: &str, p } /// Insert a trace entry into article_history for debugging pipeline behavior. +#[allow(clippy::too_many_arguments)] async fn trace_article( pool: &sqlx::PgPool, user_id: Uuid, @@ -741,6 +748,7 @@ async fn trace_article( } /// Log an LLM call with full prompt, response, and timing. +#[allow(clippy::too_many_arguments)] async fn log_llm_call( pool: &sqlx::PgPool, user_id: Uuid, @@ -1024,14 +1032,8 @@ fn rotate_sources(sources: Vec, last_source_url: } } -/// Scrape a single article URL, returning (body_text, page_title, final_url) or empty strings on failure. -/// -/// Handles all failure modes gracefully: -/// - Network errors → empty content (article kept) -/// - Soft 404 → article excluded (empty content) -/// - Article too old → article excluded (empty content) -/// Result of scraping a single article. -/// The 4th value is the drop reason if the article was rejected (None if OK). +/// Scrape a single article. Returns (body_text, page_title, final_url, drop_reason). +/// `drop_reason` is `Some("filtered_empty")` or `Some("filtered_too_old")` if rejected, `None` if OK. async fn scrape_single_article( http_client: &reqwest::Client, url: &str,