From e6df6f423bd7820b3bd29223dc25f5a4e2345687 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 28 Oct 2026 10:52:53 +0000 Subject: [PATCH] Refactor the gridcraft apps for strict Clippy checks --- apps/gridcraft-cli/src/check/fidelity.rs | 2 +- apps/gridcraft-cli/src/check/package.rs | 4 +++- apps/gridcraft-cli/src/check/report.rs | 22 +++++++++++++++++++--- apps/gridcraft-cli/tests/it/main.rs | 2 -- apps/gridcraft/src/logging.rs | 7 ++++--- apps/gridcraft/tests/mac_menu_appkit.rs | 1 - 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/gridcraft-cli/src/check/fidelity.rs b/apps/gridcraft-cli/src/check/fidelity.rs index 446a8949a..d8def2747 100644 --- a/apps/gridcraft-cli/src/check/fidelity.rs +++ b/apps/gridcraft-cli/src/check/fidelity.rs @@ -1,6 +1,6 @@ use super::calc::formula_text; use super::package::{REBUILT_KINDS, relationship_kinds, validate_package}; -use super::*; +use super::{BTreeSet, Category, Cell, CellError, CellRef, Diffs, Options, RoundTrip, Sheet, Value, Workbook, number_text, quote_sheet}; // ---------------------------------------------------------------- round trip diff --git a/apps/gridcraft-cli/src/check/package.rs b/apps/gridcraft-cli/src/check/package.rs index bcbbef10f..6b97fa495 100644 --- a/apps/gridcraft-cli/src/check/package.rs +++ b/apps/gridcraft-cli/src/check/package.rs @@ -20,7 +20,9 @@ fn local_name(name: &[u8]) -> &[u8] { } /// `(element local name, attributes)` for every start/empty element of an XML part. -fn xml_elements(xml: &[u8]) -> Result)>, String> { +type XmlElement = (String, Vec<(String, String)>); + +fn xml_elements(xml: &[u8]) -> Result, String> { use quick_xml::events::Event; let mut reader = quick_xml::Reader::from_reader(xml); let mut buf = Vec::new(); diff --git a/apps/gridcraft-cli/src/check/report.rs b/apps/gridcraft-cli/src/check/report.rs index 54227e797..6c0d6b36d 100644 --- a/apps/gridcraft-cli/src/check/report.rs +++ b/apps/gridcraft-cli/src/check/report.rs @@ -131,7 +131,7 @@ fn fit(s: &str, w: usize) -> String { if n <= w { s.to_string() } else { format!("…{}", s.chars().skip(n + 1 - w).collect::()) } } -pub(super) fn print_human(reports: &[FileReport], opts: &Options) { +fn print_file_reports(reports: &[FileReport]) { for r in reports { outln!("== {}", r.path); if let Some(e) = &r.error { @@ -186,7 +186,9 @@ pub(super) fn print_human(reports: &[FileReport], opts: &Options) { } } } - outln!(""); +} + +fn print_file_table(reports: &[FileReport]) { let w = reports.iter().map(|r| r.path.chars().count()).max().unwrap_or(4).clamp(4, 50); outln!( "{:8} {:>8} {:>8} {:>8} {:>9} {:>8} round trip", @@ -220,7 +222,9 @@ pub(super) fn print_human(reports: &[FileReport], opts: &Options) { c.volatile ); } - let t = totals(reports); +} + +fn print_rankings(t: &Totals, opts: &Options) { let top = ranked(&t.functions); if !top.is_empty() { outln!(""); @@ -239,6 +243,9 @@ pub(super) fn print_human(reports: &[FileReport], opts: &Options) { outln!(" {n:>8} {sig}"); } } +} + +fn print_totals(t: &Totals) { outln!(""); outln!("files: {} ({} opened, {} failed to open)", t.files, t.opened, t.failed); outln!( @@ -262,3 +269,12 @@ pub(super) fn print_human(reports: &[FileReport], opts: &Options) { if cats.is_empty() { String::new() } else { format!("; categories (files): {}", cats.join(", ")) } ); } + +pub(super) fn print_human(reports: &[FileReport], opts: &Options) { + print_file_reports(reports); + outln!(""); + print_file_table(reports); + let t = totals(reports); + print_rankings(&t, opts); + print_totals(&t); +} diff --git a/apps/gridcraft-cli/tests/it/main.rs b/apps/gridcraft-cli/tests/it/main.rs index 17f8db87f..5906b3967 100644 --- a/apps/gridcraft-cli/tests/it/main.rs +++ b/apps/gridcraft-cli/tests/it/main.rs @@ -1,5 +1,3 @@ //! The crate's integration tests, one module per file, built as one test binary. - -#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod cli; mod text_to_columns_quotes; diff --git a/apps/gridcraft/src/logging.rs b/apps/gridcraft/src/logging.rs index 413797378..ca7d05717 100644 --- a/apps/gridcraft/src/logging.rs +++ b/apps/gridcraft/src/logging.rs @@ -268,9 +268,10 @@ impl log::Log for AppLogger { } // Formatted before the sink is locked, so a message that logs while it is formatted can't deadlock. let thread = std::thread::current(); - #[allow(clippy::disallowed_methods)] // the desktop app (native only): wasm never runs it - let line = - format_line(×tamp(SystemTime::now()), record.level(), thread.name().unwrap_or("?"), record.target(), &record.args().to_string()); + let logged_at = gridcraft_engine::core::date::unix_now_ms() + .and_then(|milliseconds| SystemTime::UNIX_EPOCH.checked_add(std::time::Duration::from_millis(milliseconds.max(0.0) as u64))) + .unwrap_or(SystemTime::UNIX_EPOCH); + let line = format_line(×tamp(logged_at), record.level(), thread.name().unwrap_or("?"), record.target(), &record.args().to_string()); if self.stderr { // No terminal (a Windows GUI build, a closed pipe) is not an error worth reporting. let _ = std::io::stderr().write_all(line.as_bytes()); diff --git a/apps/gridcraft/tests/mac_menu_appkit.rs b/apps/gridcraft/tests/mac_menu_appkit.rs index e713f6699..8b132fd05 100644 --- a/apps/gridcraft/tests/mac_menu_appkit.rs +++ b/apps/gridcraft/tests/mac_menu_appkit.rs @@ -7,7 +7,6 @@ // unit tests compile here too without a harness to run them). #[cfg(target_os = "macos")] #[path = "../src/native_menu.rs"] -#[allow(unused_imports, dead_code)] mod native_menu; #[cfg(target_os = "macos")]