Clear compiler and Clippy warnings

This commit is contained in:
2026-09-12 22:56:35 +02:00
parent 69dc3891d1
commit 6e738822ff
12 changed files with 50 additions and 62 deletions

View File

@@ -31,7 +31,7 @@ code and an appropriate test or desktop/package observation support it.
autostart entry, and the canonical README.
- [x] Docker builds and tests the GUI feature set before packaging.
- [ ] Add automated dependency/security scanning when the toolchain provides it.
- [ ] Clippy passes with warnings treated as errors.
- [x] Clippy passes with warnings treated as errors.
## Test policy

View File

@@ -105,40 +105,6 @@ impl Config {
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_are_valid() {
let c = Config::default();
assert_eq!(c.history_limit, 100);
assert_eq!(c.pinned_limit, 25);
assert_eq!(c.max_entry_bytes, 1_048_576);
assert_eq!(c.history_retention_days, 30);
assert_eq!(c.global_shortcut, "Ctrl+Alt+V");
assert!(c.validate().is_ok());
}
#[test]
fn rejects_invalid_runtime_limits_and_shortcuts() {
let mut config = Config::default();
config.history_limit = 0;
assert!(config.validate().is_err());
config.history_limit = 100;
config.global_shortcut = "not-a-shortcut".into();
assert!(config.validate().is_err());
}
#[test]
fn accepts_supported_shortcut_modifiers() {
let mut config = Config::default();
for shortcut in ["Ctrl+Alt+V", "Ctrl+Alt+K", "Shift+F"] {
config.global_shortcut = shortcut.into();
assert!(config.validate().is_ok(), "{shortcut}");
}
}
}
fn validate_shortcut(shortcut: &str) -> Result<()> {
let parts: Vec<_> = shortcut.split('+').map(str::trim).collect();
if parts.len() < 2 || parts.last().is_some_and(|key| key.chars().count() != 1) {
@@ -156,3 +122,41 @@ fn validate_shortcut(shortcut: &str) -> Result<()> {
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_are_valid() {
let c = Config::default();
assert_eq!(c.history_limit, 100);
assert_eq!(c.pinned_limit, 25);
assert_eq!(c.max_entry_bytes, 1_048_576);
assert_eq!(c.history_retention_days, 30);
assert_eq!(c.global_shortcut, "Ctrl+Alt+V");
assert!(c.validate().is_ok());
}
#[test]
fn rejects_invalid_runtime_limits_and_shortcuts() {
let invalid_limits = Config {
history_limit: 0,
..Config::default()
};
assert!(invalid_limits.validate().is_err());
let invalid_shortcut = Config {
global_shortcut: "not-a-shortcut".into(),
..Config::default()
};
assert!(invalid_shortcut.validate().is_err());
}
#[test]
fn accepts_supported_shortcut_modifiers() {
let mut config = Config::default();
for shortcut in ["Ctrl+Alt+V", "Ctrl+Alt+K", "Shift+F"] {
config.global_shortcut = shortcut.into();
assert!(config.validate().is_ok(), "{shortcut}");
}
}
}

View File

@@ -11,6 +11,7 @@ pub struct Entry {
}
impl Entry {
#[cfg(test)]
pub fn new(id: i64, content: String, now: i64) -> Self {
let content_hash = crate::core::content_hash(&content);
Self {

View File

@@ -15,7 +15,6 @@ use fs2::FileExt;
pub struct InstanceGuard {
_file: File,
path: PathBuf,
show_requested: Arc<AtomicBool>,
quit_requested: Arc<AtomicBool>,
stop: Arc<AtomicBool>,
@@ -91,7 +90,6 @@ impl InstanceGuard {
.context("failed to start instance command listener")?;
Ok(Self {
_file: file,
path,
show_requested,
quit_requested,
stop,
@@ -99,10 +97,6 @@ impl InstanceGuard {
})
}
pub fn path(&self) -> &std::path::Path {
&self.path
}
pub fn show_requested(&self) -> Arc<AtomicBool> {
Arc::clone(&self.show_requested)
}
@@ -149,7 +143,7 @@ impl Drop for InstanceGuard {
pub fn runtime_dir() -> PathBuf {
dirs::runtime_dir()
.unwrap_or_else(|| std::env::temp_dir())
.unwrap_or_else(std::env::temp_dir)
.join("cliphoard")
}

View File

@@ -4,7 +4,7 @@ use tracing_appender::non_blocking::WorkerGuard;
const RETAINED_LOG_FILES: usize = 7;
pub enum LoggingGuard {
File(WorkerGuard),
File { _guard: WorkerGuard },
Stderr,
}
@@ -25,7 +25,7 @@ pub fn init(configured_level: &str) -> LoggingGuard {
.try_init()
.is_ok()
{
return LoggingGuard::File(guard);
return LoggingGuard::File { _guard: guard };
}
}
}

View File

@@ -62,7 +62,7 @@ fn main() -> Result<()> {
println!(
"Log directory: {}",
dirs::state_dir()
.unwrap_or_else(|| std::env::temp_dir())
.unwrap_or_else(std::env::temp_dir)
.join("cliphoard")
.display()
);

View File

@@ -4,8 +4,6 @@ mod x11_input;
#[cfg(feature = "gui")]
pub(crate) mod x11_window;
pub use x11_clipboard::{
ClipboardWorkerResult, X11Clipboard, X11ClipboardReader, X11ClipboardWorker,
};
pub use x11_clipboard::{ClipboardWorkerResult, X11ClipboardReader, X11ClipboardWorker};
pub use x11_events::{X11ClipboardWatcher, X11Hotkey};
pub use x11_input::X11Input;

View File

@@ -18,7 +18,7 @@ use crate::platform::{ClipboardBackend, InputBackend};
use super::X11Input;
pub struct X11Clipboard {
struct X11Clipboard {
clipboard: Clipboard,
input: Option<X11Input>,
}
@@ -207,9 +207,6 @@ impl X11Clipboard {
}
impl ClipboardBackend for X11Clipboard {
fn read_text(&mut self) -> Result<Option<String>> {
read_clipboard_text(&self.clipboard, usize::MAX)
}
fn write_text(&mut self, text: &str) -> Result<()> {
let atoms = &self.clipboard.setter.atoms;
self.clipboard

View File

@@ -7,7 +7,7 @@ use anyhow::{Context, Result};
use x11rb::{
connection::Connection,
protocol::{
xfixes::{self, ConnectionExt as _},
xfixes,
xproto::{self, ConnectionExt as _},
Event,
},

View File

@@ -3,7 +3,7 @@ use x11rb::{
connection::Connection,
protocol::{
xproto::{self, ConnectionExt as _},
xtest::{self, ConnectionExt as _},
xtest,
},
rust_connection::RustConnection,
};

View File

@@ -4,7 +4,6 @@ pub mod linux;
use anyhow::Result;
pub trait ClipboardBackend {
fn read_text(&mut self) -> Result<Option<String>>;
fn write_text(&mut self, text: &str) -> Result<()>;
}

View File

@@ -11,7 +11,6 @@ use rusqlite::{params, Connection};
use crate::core::{content_hash, Entry};
pub struct Database {
path: PathBuf,
connection: Connection,
}
@@ -187,11 +186,7 @@ impl Database {
}
connection.pragma_update(None, "foreign_keys", "ON")?;
migrations::run(&connection)?;
Ok(Self { path, connection })
}
pub fn path(&self) -> &Path {
&self.path
Ok(Self { connection })
}
pub fn load_entries(&self) -> Result<Vec<Entry>> {
@@ -341,7 +336,7 @@ mod tests {
let first = db.upsert_content("a", 1).unwrap();
let second = db.upsert_content("b", 2).unwrap();
assert!(db.toggle_pinned(first.id, 1).unwrap());
assert!(db.toggle_pinned(first.id, 1).unwrap() == false);
assert!(!db.toggle_pinned(first.id, 1).unwrap());
assert!(db.toggle_pinned(second.id, 1).unwrap());
}