chore(lint): clean up clippy warnings across workspace

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).
This commit is contained in:
2026-04-24 09:43:56 +01:00
parent 9b0067b4c0
commit fe61661305
11 changed files with 20 additions and 22 deletions

View File

@@ -112,7 +112,7 @@ impl MicrophoneCapture {
for device in devices { for device in devices {
let name = device_display_name(&device).unwrap_or_else(|| "<unnamed>".to_string()); let name = device_display_name(&device).unwrap_or_else(|| "<unnamed>".to_string());
let (sample_rate, channels) = match device.default_input_config() { 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), Err(_) => (0, 0),
}; };
let is_likely_monitor = is_monitor_name(&name); let is_likely_monitor = is_monitor_name(&name);
@@ -278,7 +278,7 @@ fn device_display_name(device: &cpal::Device) -> Option<String> {
fn extract_card_id(name: &str) -> Option<&str> { fn extract_card_id(name: &str) -> Option<&str> {
let rest = name.split("CARD=").nth(1)?; let rest = name.split("CARD=").nth(1)?;
Some( Some(
rest.split(|c: char| c == ',' || c == ';') rest.split([',', ';'])
.next() .next()
.unwrap_or(rest), .unwrap_or(rest),
) )
@@ -361,7 +361,7 @@ fn open_and_validate(
.default_input_config() .default_input_config()
.map_err(|e| KonError::AudioCaptureFailed(format!("default_input_config: {e}")))?; .map_err(|e| KonError::AudioCaptureFailed(format!("default_input_config: {e}")))?;
let sample_rate = config.sample_rate(); let sample_rate = config.sample_rate();
let channels = config.channels() as u16; let channels = config.channels();
let format = config.sample_format(); let format = config.sample_format();
eprintln!( eprintln!(

View File

@@ -343,14 +343,14 @@ async fn device_listener(
fn is_event_device(path: &Path) -> bool { fn is_event_device(path: &Path) -> bool {
path.file_name() path.file_name()
.and_then(|n| n.to_str()) .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 /// 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 /// configured trigger key. A device that reports no keys at all (for
/// example a mouse whose `EV_KEY` capability is buttons only) is rejected. /// example a mouse whose `EV_KEY` capability is buttons only) is rejected.
fn device_supports_combo(supported: Option<&AttributeSetRef<Key>>, combo: &HotkeyCombo) -> bool { fn device_supports_combo(supported: Option<&AttributeSetRef<Key>>, 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)] #[cfg(test)]

View File

@@ -2,11 +2,11 @@ use std::path::PathBuf;
/// Resolve the per-user app data directory, following each OS's convention: /// 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/` /// - macOS: `~/Library/Application Support/Kon/`
/// - Linux: `$XDG_DATA_HOME/kon` or `~/.local/share/kon` (XDG Base Directory), /// - Linux: `$XDG_DATA_HOME/kon` or `~/.local/share/kon` (XDG Base Directory),
/// with a fallback to the legacy `~/.kon/` if it already exists, so /// with a fallback to the legacy `~/.kon/` if it already exists, so
/// existing installs keep working. /// existing installs keep working.
/// - Other Unix: `~/.kon/` /// - Other Unix: `~/.kon/`
/// ///
/// TODO: Consolidate with `crates/transcription/src/model_manager.rs::dirs_path()` /// 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(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")))] #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]

View File

@@ -158,7 +158,7 @@ mod tests {
let mut total_pushed: u64 = 0; let mut total_pushed: u64 = 0;
let tentative_per_cycle: u64 = 200; let tentative_per_cycle: u64 = 200;
for _ in 0..100 { 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; total_pushed += 16_000;
let commit_point = total_pushed - tentative_per_cycle; let commit_point = total_pushed - tentative_per_cycle;
start = trim_buffer_to_commit_point(&mut buf, start, commit_point); 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 // Simulate a capture buffer that has received 1.2 s of audio
// starting at t=0. // starting at t=0.
let mut buf: Vec<f32> = std::iter::repeat(0.1_f32).take(19_200).collect(); let mut buf: Vec<f32> = std::iter::repeat_n(0.1_f32, 19_200).collect();
let new_start = trim_buffer_to_commit_point(&mut buf, 0, commit_idx); let new_start = trim_buffer_to_commit_point(&mut buf, 0, commit_idx);
assert_eq!(new_start, 8_000); assert_eq!(new_start, 8_000);
assert_eq!(buf.len(), 19_200 - 8_000); assert_eq!(buf.len(), 19_200 - 8_000);

View File

@@ -306,7 +306,7 @@ impl VadChunker for RmsVadChunker {
.saturating_sub(self.pending.len() as u64); .saturating_sub(self.pending.len() as u64);
let pad_len = FRAME_SAMPLES - self.pending.len(); let pad_len = FRAME_SAMPLES - self.pending.len();
let mut padded = std::mem::take(&mut self.pending); 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) { if let Some(chunk) = self.consume_frame(padded, frame_start) {
emitted.push(chunk); emitted.push(chunk);
} }

View File

@@ -64,7 +64,7 @@ fn assert_localhost_llm_csp() {
let tokens: Vec<&str> = connect_src.split_whitespace().collect(); let tokens: Vec<&str> = connect_src.split_whitespace().collect();
for required in ["http://127.0.0.1:*", "ws://127.0.0.1:*"] { for required in ["http://127.0.0.1:*", "ws://127.0.0.1:*"] {
assert!( assert!(
tokens.iter().any(|t| *t == required), tokens.contains(&required),
"build.rs: tauri.conf.json CSP connect-src must permit {required} \ "build.rs: tauri.conf.json CSP connect-src must permit {required} \
for local LLM connectivity (brief item #2). Current connect-src: \ for local LLM connectivity (brief item #2). Current connect-src: \
{connect_src:?}" {connect_src:?}"

View File

@@ -247,7 +247,7 @@ pub async fn generate_diagnostic_report(
.map(|d| d.as_secs()) .map(|d| d.as_secs())
.unwrap_or(0); .unwrap_or(0);
out.push_str(&format!("- Generated: unix `{}`\n", now)); out.push_str(&format!("- Generated: unix `{}`\n", now));
out.push_str("\n"); out.push('\n');
out.push_str( out.push_str(
"> This report is local-only until you choose to share it. \ "> This report is local-only until you choose to share it. \
Review the contents below before sending to anyone.\n\n", Review the contents below before sending to anyone.\n\n",

View File

@@ -1155,12 +1155,10 @@ fn longest_common_token_subsequence(a: &[&str], b: &[&str]) -> usize {
} }
fn is_low_signal_token(token: &str) -> bool { fn is_low_signal_token(token: &str) -> bool {
LOW_SIGNAL_TOKENS LOW_SIGNAL_TOKENS.contains(&token)
.iter()
.any(|low_signal| *low_signal == token)
} }
fn meaningful_tokens<'a>(text: &'a str) -> Vec<&'a str> { fn meaningful_tokens(text: &str) -> Vec<&str> {
text.split_whitespace() text.split_whitespace()
.filter(|token| !token.is_empty() && token.len() > 1 && !is_low_signal_token(token)) .filter(|token| !token.is_empty() && token.len() > 1 && !is_low_signal_token(token))
.collect() .collect()

View File

@@ -412,7 +412,7 @@ pub fn detect_active_compute_device() -> ActiveComputeDevice {
reason: None, reason: None,
}; };
} }
return ActiveComputeDevice { ActiveComputeDevice {
kind: "cpu".into(), kind: "cpu".into(),
label: "CPU (fallback)".into(), label: "CPU (fallback)".into(),
reason: Some( reason: Some(
@@ -420,7 +420,7 @@ pub fn detect_active_compute_device() -> ActiveComputeDevice {
libvulkan1 (Linux) to enable GPU acceleration." libvulkan1 (Linux) to enable GPU acceleration."
.into(), .into(),
), ),
}; }
} }
} }

View File

@@ -345,7 +345,7 @@ fn classify_terminal(raw: &str) -> Option<String> {
fn detect_focused_window_class() -> Option<String> { fn detect_focused_window_class() -> Option<String> {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
return detect_focused_window_class_linux(); detect_focused_window_class_linux()
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {

View File

@@ -234,7 +234,7 @@ pub fn run() {
// Runtime-warning banner: push CPU-feature + Vulkan-loader // Runtime-warning banner: push CPU-feature + Vulkan-loader
// fallbacks to the frontend so Settings can render a one-line // fallbacks to the frontend so Settings can render a one-line
// hint. No-ops on a fully-supported box. // 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) { if let Err(e) = tray::setup(app) {
eprintln!("Failed to setup tray: {e}"); eprintln!("Failed to setup tray: {e}");