From b4e1113f3d4e8dceac3eef65d50ec13dc8938249 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 4 Dec 2024 14:36:59 +0100 Subject: [PATCH] chore: add linter config and related code cleanup --- Cargo.toml | 12 ++++++++++ src/commands.rs | 46 ++++++++++++++++++++++++--------------- src/model/requirements.rs | 3 +-- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d66c8f9..0620ded 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,18 @@ lto = "thin" strip = true panic = "abort" +# Lints + +[lints.clippy] +unwrap_used = "deny" +expect_used = "deny" +panic = "deny" + +[lints.rust] +unused_must_use = "deny" + +# Packaging + [package.metadata.deb] copyright = "Copyright (C) 2023-2024 the original author or authors" extended-description = "Anwendung zum Anpassen einer OSC-Datei an einen Standort." diff --git a/src/commands.rs b/src/commands.rs index f2403cb..db8959d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -178,25 +178,33 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { let mut strip = strip; if interactive { - compact = Confirm::new() - .with_prompt("Kompakte Ausgabe, ohne Einrücken?") - .default(compact) - .interact() - .unwrap(); + compact = matches!( + Confirm::new() + .with_prompt("Kompakte Ausgabe, ohne Einrücken?") + .default(compact) + .interact(), + Ok(true) + ); - sorted = Confirm::new() - .with_prompt("Sortiere Kataloge und Formulare nach Name und Abhängigkeiten?") - .default(sorted) - .interact() - .unwrap(); + sorted = matches!( + Confirm::new() + .with_prompt( + "Sortiere Kataloge und Formulare nach Name und Abhängigkeiten?" + ) + .default(sorted) + .interact(), + Ok(true) + ); - strip = Confirm::new() - .with_prompt( - "Entferne Einträge aus der Systembibliothek die nicht importiert werden?", - ) - .default(strip) - .interact() - .unwrap(); + strip = matches!( + Confirm::new() + .with_prompt( + "Entferne Einträge aus der Systembibliothek die nicht importiert werden?", + ) + .default(strip) + .interact(), + Ok(true) + ); } if fix { @@ -218,7 +226,9 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { serializer.indent(' ', 2); } - data.serialize(serializer).expect("Generated XML"); + data.serialize(serializer).map_err(|_| { + FileError::Writing("Cannot serialize result".to_string(), String::new()) + })?; let output = &"\n" .to_string() diff --git a/src/model/requirements.rs b/src/model/requirements.rs index a1da42a..c741825 100644 --- a/src/model/requirements.rs +++ b/src/model/requirements.rs @@ -123,8 +123,7 @@ where } _ => None, }) - .filter(Option::is_some) - .map(|item| format!(" - {}\n", item.unwrap())) + .filter_map(|item| item.map(|item| format!(" - {item}\n"))) .collect::>() .join("");