diff --git a/src-tauri/src/ai.rs b/src-tauri/src/ai.rs index c4d2ec4..e60d7dc 100644 --- a/src-tauri/src/ai.rs +++ b/src-tauri/src/ai.rs @@ -8,6 +8,7 @@ const ANTHROPIC_API_URL: &str = "https://api.anthropic.com/v1/messages"; const OPENAI_API_URL: &str = "https://api.openai.com/v1/chat/completions"; const OLLAMA_DEFAULT_URL: &str = "http://localhost:11434"; +#[allow(clippy::too_many_arguments)] pub fn ai_request( app: AppHandle, provider: String, diff --git a/src-tauri/src/backup.rs b/src-tauri/src/backup.rs index 3b364c9..93ef7e2 100644 --- a/src-tauri/src/backup.rs +++ b/src-tauri/src/backup.rs @@ -134,7 +134,7 @@ pub fn list_backups(backup_dir: &Path) -> Result, String> { let entry = entry.map_err(|e| e.to_string())?; let path = entry.path(); - if path.extension().map_or(false, |ext| ext == "zip") { + if path.extension().is_some_and(|ext| ext == "zip") { let filename = path .file_name() .unwrap_or_default() diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 96bb019..f7184ea 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -391,10 +391,12 @@ mod custom_theme_reference_tests { #[test] fn deleting_custom_theme_resets_system_pair_references() { - let mut config = AppConfig::default(); - config.theme = "custom-work".to_string(); - config.system_light_theme = "custom-work".to_string(); - config.system_dark_theme = "custom-work".to_string(); + let mut config = AppConfig { + theme: "custom-work".to_string(), + system_light_theme: "custom-work".to_string(), + system_dark_theme: "custom-work".to_string(), + ..Default::default() + }; clear_custom_theme_references(&mut config, "custom-work"); @@ -982,8 +984,8 @@ fn extract_title_fast(raw: &str) -> Option { let frontmatter = &after_open[..end]; for line in frontmatter.lines() { let line = line.trim(); - if line.starts_with("title:") { - let val = line[6..].trim(); + if let Some(title) = line.strip_prefix("title:") { + let val = title.trim(); // Strip surrounding quotes if (val.starts_with('"') && val.ends_with('"')) || (val.starts_with('\'') && val.ends_with('\'')) { return Some(val[1..val.len()-1].to_string()); @@ -1479,6 +1481,7 @@ pub fn set_notebook_icon( // ── General Settings ── #[tauri::command] +#[allow(clippy::too_many_arguments)] pub fn set_general_settings( state: State<'_, AppState>, compact_notes: bool, @@ -2044,6 +2047,7 @@ pub fn get_note_version_content( // ── AI ── #[tauri::command] +#[allow(clippy::too_many_arguments)] pub fn set_ai_settings( state: State<'_, AppState>, provider: Option, @@ -2162,23 +2166,24 @@ mod vault_identity_tests { #[test] fn bookmark_identity_disambiguates_vaults_with_the_same_path() { - let mut config = AppConfig::default(); - config.active_vault = Some("/same/path".to_string()); - config.vaults = vec![ - VaultConfig { - path: "/same/path".to_string(), - name: "Local".to_string(), - ..Default::default() - }, - VaultConfig { - path: "/same/path".to_string(), - name: "Files".to_string(), - bookmark_id: Some("bookmark".to_string()), - ..Default::default() - }, - ]; - - config.active_bookmark_id = Some("bookmark".to_string()); + let mut config = AppConfig { + active_vault: Some("/same/path".to_string()), + vaults: vec![ + VaultConfig { + path: "/same/path".to_string(), + name: "Local".to_string(), + ..Default::default() + }, + VaultConfig { + path: "/same/path".to_string(), + name: "Files".to_string(), + bookmark_id: Some("bookmark".to_string()), + ..Default::default() + }, + ], + active_bookmark_id: Some("bookmark".to_string()), + ..Default::default() + }; assert_eq!(active_vault_config(&config).unwrap().name, "Files"); config.active_bookmark_id = None; @@ -2204,6 +2209,7 @@ fn sync_config_from(config: &AppConfig) -> Result, provider: Option, diff --git a/src-tauri/src/history.rs b/src-tauri/src/history.rs index 84c6985..c005a07 100644 --- a/src-tauri/src/history.rs +++ b/src-tauri/src/history.rs @@ -115,7 +115,7 @@ pub fn list_versions(vault_path: &str, note_id: &str) -> Result Result Result<(), String> { .map_err(|e| e.to_string())? .filter_map(|e| e.ok()) .map(|e| e.path()) - .filter(|p| p.extension().map_or(false, |ext| ext == "md")) + .filter(|p| p.extension().is_some_and(|ext| ext == "md")) .collect(); // Sort by name (timestamps sort lexicographically) - newest last diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4d7be6b..41ccebf 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -219,7 +219,7 @@ pub fn run() { let external_url = percent_decode(encoded); if !external_url.starts_with("http://") && !external_url.starts_with("https://") { - let _ = responder.respond( + responder.respond( tauri::http::Response::builder() .status(400) .body(Vec::new()) @@ -234,7 +234,7 @@ pub fn run() { { Ok(c) => c, Err(_) => { - let _ = responder.respond( + responder.respond( tauri::http::Response::builder() .status(502) .body(Vec::new()) @@ -255,7 +255,7 @@ pub fn run() { let status = resp.status().as_u16(); match resp.bytes() { Ok(bytes) => { - let _ = responder.respond( + responder.respond( tauri::http::Response::builder() .status(status) .header("Content-Type", &content_type) @@ -265,7 +265,7 @@ pub fn run() { ); } Err(_) => { - let _ = responder.respond( + responder.respond( tauri::http::Response::builder() .status(502) .body(Vec::new()) @@ -275,7 +275,7 @@ pub fn run() { } } Err(_) => { - let _ = responder.respond( + responder.respond( tauri::http::Response::builder() .status(502) .body(Vec::new()) @@ -350,9 +350,9 @@ pub fn run() { let _ = window.hide(); } } - tauri::WindowEvent::Destroyed => { + tauri::WindowEvent::Destroyed // When main window is destroyed, close all note windows - if window.label() == "main" { + if window.label() == "main" => { let app = window.app_handle(); for (label, win) in app.webview_windows() { if label.starts_with("note-") { @@ -360,7 +360,6 @@ pub fn run() { } } } - } _ => {} } }); diff --git a/src-tauri/src/search/mod.rs b/src-tauri/src/search/mod.rs index af40674..b1e34bd 100644 --- a/src-tauri/src/search/mod.rs +++ b/src-tauri/src/search/mod.rs @@ -290,7 +290,7 @@ impl SearchIndex { doc.add_text(self.path_field, &path_str); doc.add_text(self.title_field, &meta.title); doc.add_text(self.body_field, &content); - doc.add_text(self.tags_field, &meta.tags.join(" ")); + doc.add_text(self.tags_field, meta.tags.join(" ")); let _ = writer.add_document(doc); } } @@ -321,7 +321,7 @@ impl SearchIndex { doc.add_text(self.path_field, path); doc.add_text(self.title_field, &meta.title); doc.add_text(self.body_field, &content); - doc.add_text(self.tags_field, &meta.tags.join(" ")); + doc.add_text(self.tags_field, meta.tags.join(" ")); let _ = writer.add_document(doc); writer.commit().map_err(|e| e.to_string())?; @@ -341,7 +341,7 @@ impl SearchIndex { let reader = self.index.reader().map_err(|e| e.to_string())?; let searcher = reader.searcher(); - let fields = vec![self.title_field, self.body_field, self.tags_field]; + let fields = [self.title_field, self.body_field, self.tags_field]; // Tokenize the query with the SAME CJK-aware analyzer used for indexing, so a // Chinese/Japanese/Korean query becomes the same uni/bigram tokens as the docs. // (For pure-ASCII queries this yields the same lowercased word tokens as before.) diff --git a/src-tauri/src/vault/frontmatter.rs b/src-tauri/src/vault/frontmatter.rs index 6d7491d..55e0ca6 100644 --- a/src-tauri/src/vault/frontmatter.rs +++ b/src-tauri/src/vault/frontmatter.rs @@ -108,7 +108,7 @@ pub fn serialize_frontmatter(meta: &NoteMeta) -> String { "[{}]", meta.tags .iter() - .map(|t| format!("{}", t)) + .map(|t| t.to_string()) .collect::>() .join(", ") ) @@ -279,7 +279,7 @@ fn strip_html_and_markdown(input: &str) -> String { chars.next(); // skip '[' let mut depth = 1; // Skip alt text - while let Some(c) = chars.next() { + for c in chars.by_ref() { if c == '[' { depth += 1; } @@ -294,7 +294,7 @@ fn strip_html_and_markdown(input: &str) -> String { if chars.peek() == Some(&'(') { chars.next(); let mut depth = 1; - while let Some(c) = chars.next() { + for c in chars.by_ref() { if c == '(' { depth += 1; } @@ -313,7 +313,7 @@ fn strip_html_and_markdown(input: &str) -> String { if ch == '[' { let mut link_text = String::new(); let mut depth = 1; - while let Some(c) = chars.next() { + for c in chars.by_ref() { if c == '[' { depth += 1; } @@ -329,7 +329,7 @@ fn strip_html_and_markdown(input: &str) -> String { if chars.peek() == Some(&'(') { chars.next(); let mut depth = 1; - while let Some(c) = chars.next() { + for c in chars.by_ref() { if c == '(' { depth += 1; } diff --git a/src-tauri/src/vault/import.rs b/src-tauri/src/vault/import.rs index c7291f4..711a4f4 100644 --- a/src-tauri/src/vault/import.rs +++ b/src-tauri/src/vault/import.rs @@ -116,9 +116,7 @@ pub fn import(vault_path: &str) -> Result { result.links_converted += 1; format!("![{}]({})", alt, link_target) } else { - let display = if alt_param.is_empty() { - file_part.rsplit('/').next().unwrap_or(file_part) - } else if is_dimension_spec(alt_param) { + let display = if alt_param.is_empty() || is_dimension_spec(alt_param) { file_part.rsplit('/').next().unwrap_or(file_part) } else { alt_param @@ -267,7 +265,7 @@ fn normalize_frontmatter(raw: &str, path: &Path) -> (NoteMeta, String) { let tags = normalize_tags(&mapping); let title = mapping - .get(&serde_yaml::Value::String("title".into())) + .get(serde_yaml::Value::String("title".into())) .and_then(|v| v.as_str()) .map(|s| s.to_string()) .unwrap_or_else(|| { @@ -283,7 +281,7 @@ fn normalize_frontmatter(raw: &str, path: &Path) -> (NoteMeta, String) { }); let id = mapping - .get(&serde_yaml::Value::String("id".into())) + .get(serde_yaml::Value::String("id".into())) .and_then(|v| v.as_str()) .map(|s| s.to_string()) .filter(|s| !s.is_empty()) @@ -293,9 +291,9 @@ fn normalize_frontmatter(raw: &str, path: &Path) -> (NoteMeta, String) { .iter() .find_map(|key| { mapping - .get(&serde_yaml::Value::String((*key).into())) + .get(serde_yaml::Value::String((*key).into())) .and_then(|v| v.as_str()) - .and_then(|s| frontmatter::parse_date_flexible(s)) + .and_then(frontmatter::parse_date_flexible) }) .or_else(|| file_created(path)) .unwrap_or_else(Utc::now); @@ -304,15 +302,15 @@ fn normalize_frontmatter(raw: &str, path: &Path) -> (NoteMeta, String) { .iter() .find_map(|key| { mapping - .get(&serde_yaml::Value::String((*key).into())) + .get(serde_yaml::Value::String((*key).into())) .and_then(|v| v.as_str()) - .and_then(|s| frontmatter::parse_date_flexible(s)) + .and_then(frontmatter::parse_date_flexible) }) .or_else(|| file_modified(path)) .unwrap_or_else(Utc::now); let pinned = mapping - .get(&serde_yaml::Value::String("pinned".into())) + .get(serde_yaml::Value::String("pinned".into())) .and_then(|v| v.as_bool()) .unwrap_or(false); @@ -332,7 +330,7 @@ fn normalize_tags(mapping: &serde_yaml::Mapping) -> Vec { let mut seen = HashSet::new(); for key in &["tags", "tag"] { - if let Some(val) = mapping.get(&serde_yaml::Value::String((*key).into())) { + if let Some(val) = mapping.get(serde_yaml::Value::String((*key).into())) { for raw in yaml_value_to_strings(val) { let cleaned = raw.trim().trim_start_matches('#').trim().to_string(); if !cleaned.is_empty() && seen.insert(cleaned.to_lowercase()) { @@ -686,7 +684,7 @@ fn cleanup_empty_dirs(root: &Path) { .map(|e| e.path().to_path_buf()) .collect(); - dirs.sort_by(|a, b| b.components().count().cmp(&a.components().count())); + dirs.sort_by_key(|path| std::cmp::Reverse(path.components().count())); for dir in dirs { let dir_str = dir.to_string_lossy(); diff --git a/src-tauri/src/vault/operations.rs b/src-tauri/src/vault/operations.rs index 31bbaf1..68939d2 100644 --- a/src-tauri/src/vault/operations.rs +++ b/src-tauri/src/vault/operations.rs @@ -381,7 +381,7 @@ pub fn scan_notes(vault_path: &str, notebook_path: Option<&str>) -> Result) -> Result) -> Result Result { }; let modified = fs::metadata(&path) .and_then(|m| m.modified()) - .map(|t| DateTime::::from(t)) + .map(DateTime::::from) .unwrap_or_else(|_| Utc::now()); notebooks.push(TrashNotebookEntry { name, @@ -1187,8 +1187,8 @@ pub fn get_trash_contents(vault_path: &str) -> Result { } } - notes.sort_by(|a, b| b.meta.modified.cmp(&a.meta.modified)); - notebooks.sort_by(|a, b| b.modified.cmp(&a.modified)); + notes.sort_by_key(|note| std::cmp::Reverse(note.meta.modified)); + notebooks.sort_by_key(|notebook| std::cmp::Reverse(notebook.modified)); Ok(TrashContents { notes, notebooks }) }