From 1f5f95c8f3b98c33325648f3244b22db74d7de92 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Sun, 25 Jan 2026 23:48:14 -0800 Subject: [PATCH] style: fix strict clippy and TypeScript type errors - Fix assertions on constants in clipboard.rs (use const blocks) - Fix unnecessary unwrap after is_ok check in git.rs - Remove redundant u64 >= 0 comparison in stats.rs - Add #[allow(clippy::useless_vec)] to sorting tests - Add missing beforeEach import to vitest.setup.ts - Change global.Audio to globalThis.Audio in notifications.test.ts - Add type annotations to fix null type narrowing in conversations.test.ts --- src-tauri/src/clipboard.rs | 7 +++++-- src-tauri/src/git.rs | 4 ++-- src-tauri/src/quick_actions.rs | 2 ++ src-tauri/src/sessions.rs | 1 + src-tauri/src/snippets.rs | 3 +++ src-tauri/src/stats.rs | 5 ++--- src/lib/notifications/notifications.test.ts | 10 +++++----- src/lib/stores/conversations.test.ts | 6 +++--- vitest.setup.ts | 2 +- 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src-tauri/src/clipboard.rs b/src-tauri/src/clipboard.rs index 960ea38..d83ecc5 100644 --- a/src-tauri/src/clipboard.rs +++ b/src-tauri/src/clipboard.rs @@ -408,13 +408,15 @@ mod tests { #[test] fn test_max_history_size_is_reasonable() { assert_eq!(MAX_HISTORY_SIZE, 100); - assert!(MAX_HISTORY_SIZE > 0); - assert!(MAX_HISTORY_SIZE <= 1000); // Sanity check + // Compile-time assertions for constant bounds + const _: () = assert!(MAX_HISTORY_SIZE > 0); + const _: () = assert!(MAX_HISTORY_SIZE <= 1000); // Sanity check } // ==================== Pinned entry sorting tests ==================== #[test] + #[allow(clippy::useless_vec)] fn test_pinned_entries_sorting() { let mut entries = vec![ ClipboardEntry { @@ -464,6 +466,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_multiple_pinned_entries_sorting() { let mut entries = vec![ ClipboardEntry { diff --git a/src-tauri/src/git.rs b/src-tauri/src/git.rs index f6a6076..8a3fd9e 100644 --- a/src-tauri/src/git.rs +++ b/src-tauri/src/git.rs @@ -733,8 +733,8 @@ mod tests { let result = git_log(working_dir, Some(10)); // May fail on empty repo or return empty - if result.is_ok() { - assert!(result.unwrap().is_empty()); + if let Ok(commits) = result { + assert!(commits.is_empty()); } } diff --git a/src-tauri/src/quick_actions.rs b/src-tauri/src/quick_actions.rs index d26d5d0..96766f6 100644 --- a/src-tauri/src/quick_actions.rs +++ b/src-tauri/src/quick_actions.rs @@ -247,6 +247,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_quick_action_sorting_defaults_first() { let mut actions = vec![ create_test_action("custom-z", "Zebra", false), @@ -354,6 +355,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_action_find_by_id() { let actions = vec![ create_test_action("action-1", "First", false), diff --git a/src-tauri/src/sessions.rs b/src-tauri/src/sessions.rs index eba2f46..42dca83 100644 --- a/src-tauri/src/sessions.rs +++ b/src-tauri/src/sessions.rs @@ -321,6 +321,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_session_sorting_by_activity() { let old_time = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap(); let new_time = Utc.with_ymd_and_hms(2024, 6, 15, 12, 0, 0).unwrap(); diff --git a/src-tauri/src/snippets.rs b/src-tauri/src/snippets.rs index 73de495..dffa028 100644 --- a/src-tauri/src/snippets.rs +++ b/src-tauri/src/snippets.rs @@ -281,6 +281,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_snippet_sorting_by_category_then_name() { let mut snippets = vec![ create_test_snippet("s1", "Zebra", "B-Category", false), @@ -388,6 +389,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_snippet_find_by_id() { let snippets = vec![ create_test_snippet("snippet-1", "First", "Cat", false), @@ -404,6 +406,7 @@ mod tests { } #[test] + #[allow(clippy::useless_vec)] fn test_extract_categories_sorted_and_deduped() { let snippets = vec![ create_test_snippet("s1", "S1", "Zebra", false), diff --git a/src-tauri/src/stats.rs b/src-tauri/src/stats.rs index 0b6dc11..36d08fe 100644 --- a/src-tauri/src/stats.rs +++ b/src-tauri/src/stats.rs @@ -523,9 +523,8 @@ mod tests { let mut stats = UsageStats::new(); stats.session_start = Some(Instant::now()); - // The duration should be at least 0 seconds - let duration = stats.get_session_duration(); - assert!(duration >= 0); + // Verify duration is returned (u64 is always non-negative) + let _duration = stats.get_session_duration(); } #[test] diff --git a/src/lib/notifications/notifications.test.ts b/src/lib/notifications/notifications.test.ts index 2763266..e730dff 100644 --- a/src/lib/notifications/notifications.test.ts +++ b/src/lib/notifications/notifications.test.ts @@ -23,7 +23,7 @@ class MockAudioElement { } // Store original Audio before mocking -const OriginalAudio = global.Audio; +const OriginalAudio = globalThis.Audio; describe("notifications", () => { describe("NotificationType enum", () => { @@ -162,12 +162,12 @@ describe("notifications", () => { describe("SoundPlayer class", () => { beforeEach(() => { // Mock Audio constructor - global.Audio = MockAudioElement as unknown as typeof Audio; + globalThis.Audio = MockAudioElement as unknown as typeof Audio; }); afterEach(() => { // Restore original Audio - global.Audio = OriginalAudio; + globalThis.Audio = OriginalAudio; vi.resetModules(); }); @@ -232,12 +232,12 @@ describe("notifications", () => { describe("NotificationManager class", () => { beforeEach(() => { - global.Audio = MockAudioElement as unknown as typeof Audio; + globalThis.Audio = MockAudioElement as unknown as typeof Audio; vi.resetModules(); }); afterEach(() => { - global.Audio = OriginalAudio; + globalThis.Audio = OriginalAudio; }); it("can import notificationManager singleton", async () => { diff --git a/src/lib/stores/conversations.test.ts b/src/lib/stores/conversations.test.ts index 7e4852f..ddc2d0a 100644 --- a/src/lib/stores/conversations.test.ts +++ b/src/lib/stores/conversations.test.ts @@ -328,7 +328,7 @@ describe("scroll position handling", () => { }); it("uses positive values for manual scroll position", () => { - const scrollPosition = 500; + const scrollPosition: number = 500; const isAutoScroll = scrollPosition === -1; expect(isAutoScroll).toBe(false); @@ -461,7 +461,7 @@ describe("derived store behavior", () => { }); it("defaults to disconnected when no active conversation", () => { - const activeConv = null; + const activeConv = null as { connectionStatus?: string } | null; const derivedStatus = activeConv?.connectionStatus || "disconnected"; expect(derivedStatus).toBe("disconnected"); @@ -480,7 +480,7 @@ describe("derived store behavior", () => { }); it("defaults to empty array when no active conversation", () => { - const activeConv = null; + const activeConv = null as { terminalLines?: Array<{ id: string; content: string }> } | null; const derivedLines = activeConv?.terminalLines || []; expect(derivedLines).toEqual([]); diff --git a/vitest.setup.ts b/vitest.setup.ts index 79fdc85..11f6172 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -1,5 +1,5 @@ import "@testing-library/jest-dom/vitest"; -import { vi } from "vitest"; +import { vi, beforeEach } from "vitest"; // Mock Tauri invoke API const mockInvokeResults: Record = {};