From fe616613057ede0febcb9c8ea82ab84943f808cc Mon Sep 17 00:00:00 2001 From: Jake Date: Fri, 24 Apr 2026 09:43:56 +0100 Subject: [PATCH] chore(lint): clean up clippy warnings across workspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auto-applied cargo clippy --fix across 11 files — needless return, unnecessary cast, map_or simplification, repeat().take() → repeat_n(), iter().any() → contains(), manual char comparison, lifetime elision, push_str single-char, reference immediately dereferenced. Also fixed three lints on file_storage.rs manually: two doc-list-item overindentations, plus the same needless-return. Baseline main was not clippy-clean with -D warnings before; after this pass one needless_range_loop warning remains (live.rs:1089) that clippy's suggested rewrite would make less readable — left for a dedicated refactor session. Build + workspace tests remain green (245 passing, 0 failing, 1 ignored). --- crates/audio/src/capture.rs | 6 +++--- crates/hotkey/src/linux.rs | 4 ++-- crates/storage/src/file_storage.rs | 8 ++++---- crates/transcription/src/streaming/buffer_trim.rs | 4 ++-- crates/transcription/src/streaming/rms_vad.rs | 2 +- src-tauri/build.rs | 2 +- src-tauri/src/commands/diagnostics.rs | 2 +- src-tauri/src/commands/live.rs | 6 ++---- src-tauri/src/commands/models.rs | 4 ++-- src-tauri/src/commands/paste.rs | 2 +- src-tauri/src/lib.rs | 2 +- 11 files changed, 20 insertions(+), 22 deletions(-) diff --git a/crates/audio/src/capture.rs b/crates/audio/src/capture.rs index e2b3f87..b45fccd 100644 --- a/crates/audio/src/capture.rs +++ b/crates/audio/src/capture.rs @@ -112,7 +112,7 @@ impl MicrophoneCapture { for device in devices { let name = device_display_name(&device).unwrap_or_else(|| "".to_string()); let (sample_rate, channels) = match device.default_input_config() { - Ok(cfg) => (cfg.sample_rate(), cfg.channels() as u16), + Ok(cfg) => (cfg.sample_rate(), cfg.channels()), Err(_) => (0, 0), }; let is_likely_monitor = is_monitor_name(&name); @@ -278,7 +278,7 @@ fn device_display_name(device: &cpal::Device) -> Option { fn extract_card_id(name: &str) -> Option<&str> { let rest = name.split("CARD=").nth(1)?; Some( - rest.split(|c: char| c == ',' || c == ';') + rest.split([',', ';']) .next() .unwrap_or(rest), ) @@ -361,7 +361,7 @@ fn open_and_validate( .default_input_config() .map_err(|e| KonError::AudioCaptureFailed(format!("default_input_config: {e}")))?; let sample_rate = config.sample_rate(); - let channels = config.channels() as u16; + let channels = config.channels(); let format = config.sample_format(); eprintln!( diff --git a/crates/hotkey/src/linux.rs b/crates/hotkey/src/linux.rs index 5a5febf..73fc19d 100644 --- a/crates/hotkey/src/linux.rs +++ b/crates/hotkey/src/linux.rs @@ -343,14 +343,14 @@ async fn device_listener( fn is_event_device(path: &Path) -> bool { path.file_name() .and_then(|n| n.to_str()) - .map_or(false, |n| n.starts_with("event")) + .is_some_and(|n| n.starts_with("event")) } /// Return true when the device's reported key set includes the combo's /// configured trigger key. A device that reports no keys at all (for /// example a mouse whose `EV_KEY` capability is buttons only) is rejected. fn device_supports_combo(supported: Option<&AttributeSetRef>, combo: &HotkeyCombo) -> bool { - supported.map_or(false, |keys| keys.contains(Key::new(combo.key_code))) + supported.is_some_and(|keys| keys.contains(Key::new(combo.key_code))) } #[cfg(test)] diff --git a/crates/storage/src/file_storage.rs b/crates/storage/src/file_storage.rs index c7d8bdf..85f3dac 100644 --- a/crates/storage/src/file_storage.rs +++ b/crates/storage/src/file_storage.rs @@ -2,11 +2,11 @@ use std::path::PathBuf; /// Resolve the per-user app data directory, following each OS's convention: /// -/// - Windows: `%LOCALAPPDATA%\kon\` e.g. `C:\Users\Jake\AppData\Local\kon` +/// - Windows: `%LOCALAPPDATA%\kon\` — e.g. `C:\Users\Jake\AppData\Local\kon` /// - macOS: `~/Library/Application Support/Kon/` /// - Linux: `$XDG_DATA_HOME/kon` or `~/.local/share/kon` (XDG Base Directory), -/// with a fallback to the legacy `~/.kon/` if it already exists, so -/// existing installs keep working. +/// with a fallback to the legacy `~/.kon/` if it already exists, so +/// existing installs keep working. /// - Other Unix: `~/.kon/` /// /// TODO: Consolidate with `crates/transcription/src/model_manager.rs::dirs_path()` @@ -45,7 +45,7 @@ pub fn app_data_dir() -> PathBuf { return PathBuf::from(xdg).join("kon"); } } - return PathBuf::from(home).join(".local").join("share").join("kon"); + PathBuf::from(home).join(".local").join("share").join("kon") } #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))] diff --git a/crates/transcription/src/streaming/buffer_trim.rs b/crates/transcription/src/streaming/buffer_trim.rs index e7bda4a..c398ff6 100644 --- a/crates/transcription/src/streaming/buffer_trim.rs +++ b/crates/transcription/src/streaming/buffer_trim.rs @@ -158,7 +158,7 @@ mod tests { let mut total_pushed: u64 = 0; let tentative_per_cycle: u64 = 200; for _ in 0..100 { - buf.extend(std::iter::repeat(0.25_f32).take(16_000)); + buf.extend(std::iter::repeat_n(0.25_f32, 16_000)); total_pushed += 16_000; let commit_point = total_pushed - tentative_per_cycle; start = trim_buffer_to_commit_point(&mut buf, start, commit_point); @@ -199,7 +199,7 @@ mod tests { // Simulate a capture buffer that has received 1.2 s of audio // starting at t=0. - let mut buf: Vec = std::iter::repeat(0.1_f32).take(19_200).collect(); + let mut buf: Vec = std::iter::repeat_n(0.1_f32, 19_200).collect(); let new_start = trim_buffer_to_commit_point(&mut buf, 0, commit_idx); assert_eq!(new_start, 8_000); assert_eq!(buf.len(), 19_200 - 8_000); diff --git a/crates/transcription/src/streaming/rms_vad.rs b/crates/transcription/src/streaming/rms_vad.rs index de2cdcd..2a3fb2e 100644 --- a/crates/transcription/src/streaming/rms_vad.rs +++ b/crates/transcription/src/streaming/rms_vad.rs @@ -306,7 +306,7 @@ impl VadChunker for RmsVadChunker { .saturating_sub(self.pending.len() as u64); let pad_len = FRAME_SAMPLES - self.pending.len(); let mut padded = std::mem::take(&mut self.pending); - padded.extend(std::iter::repeat(0.0_f32).take(pad_len)); + padded.extend(std::iter::repeat_n(0.0_f32, pad_len)); if let Some(chunk) = self.consume_frame(padded, frame_start) { emitted.push(chunk); } diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 0ed0955..83820c6 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -64,7 +64,7 @@ fn assert_localhost_llm_csp() { let tokens: Vec<&str> = connect_src.split_whitespace().collect(); for required in ["http://127.0.0.1:*", "ws://127.0.0.1:*"] { assert!( - tokens.iter().any(|t| *t == required), + tokens.contains(&required), "build.rs: tauri.conf.json CSP connect-src must permit {required} \ for local LLM connectivity (brief item #2). Current connect-src: \ {connect_src:?}" diff --git a/src-tauri/src/commands/diagnostics.rs b/src-tauri/src/commands/diagnostics.rs index 87cc64a..57608a2 100644 --- a/src-tauri/src/commands/diagnostics.rs +++ b/src-tauri/src/commands/diagnostics.rs @@ -247,7 +247,7 @@ pub async fn generate_diagnostic_report( .map(|d| d.as_secs()) .unwrap_or(0); out.push_str(&format!("- Generated: unix `{}`\n", now)); - out.push_str("\n"); + out.push('\n'); out.push_str( "> This report is local-only until you choose to share it. \ Review the contents below before sending to anyone.\n\n", diff --git a/src-tauri/src/commands/live.rs b/src-tauri/src/commands/live.rs index 3b3977f..c71d5ef 100644 --- a/src-tauri/src/commands/live.rs +++ b/src-tauri/src/commands/live.rs @@ -1155,12 +1155,10 @@ fn longest_common_token_subsequence(a: &[&str], b: &[&str]) -> usize { } fn is_low_signal_token(token: &str) -> bool { - LOW_SIGNAL_TOKENS - .iter() - .any(|low_signal| *low_signal == token) + LOW_SIGNAL_TOKENS.contains(&token) } -fn meaningful_tokens<'a>(text: &'a str) -> Vec<&'a str> { +fn meaningful_tokens(text: &str) -> Vec<&str> { text.split_whitespace() .filter(|token| !token.is_empty() && token.len() > 1 && !is_low_signal_token(token)) .collect() diff --git a/src-tauri/src/commands/models.rs b/src-tauri/src/commands/models.rs index 21d32d1..fedccee 100644 --- a/src-tauri/src/commands/models.rs +++ b/src-tauri/src/commands/models.rs @@ -412,7 +412,7 @@ pub fn detect_active_compute_device() -> ActiveComputeDevice { reason: None, }; } - return ActiveComputeDevice { + ActiveComputeDevice { kind: "cpu".into(), label: "CPU (fallback)".into(), reason: Some( @@ -420,7 +420,7 @@ pub fn detect_active_compute_device() -> ActiveComputeDevice { libvulkan1 (Linux) to enable GPU acceleration." .into(), ), - }; + } } } diff --git a/src-tauri/src/commands/paste.rs b/src-tauri/src/commands/paste.rs index 2f9a3e1..57b098f 100644 --- a/src-tauri/src/commands/paste.rs +++ b/src-tauri/src/commands/paste.rs @@ -345,7 +345,7 @@ fn classify_terminal(raw: &str) -> Option { fn detect_focused_window_class() -> Option { #[cfg(target_os = "linux")] { - return detect_focused_window_class_linux(); + detect_focused_window_class_linux() } #[cfg(target_os = "macos")] { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 52c2064..8755b4a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -234,7 +234,7 @@ pub fn run() { // Runtime-warning banner: push CPU-feature + Vulkan-loader // fallbacks to the frontend so Settings can render a one-line // hint. No-ops on a fully-supported box. - crate::commands::models::emit_runtime_warnings(&app.handle()); + crate::commands::models::emit_runtime_warnings(app.handle()); if let Err(e) = tray::setup(app) { eprintln!("Failed to setup tray: {e}");