style: fix strict clippy and TypeScript type errors
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 56s
CI / Lint & Test (pull_request) Successful in 15m50s
CI / Build Linux (pull_request) Successful in 19m46s
CI / Build Windows (cross-compile) (pull_request) Successful in 29m28s

- 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
This commit is contained in:
2026-01-25 23:48:14 -08:00
parent be25152eea
commit 1f5f95c8f3
9 changed files with 24 additions and 16 deletions
+5 -2
View File
@@ -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 {
+2 -2
View File
@@ -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());
}
}
+2
View File
@@ -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),
+1
View File
@@ -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();
+3
View File
@@ -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),
+2 -3
View File
@@ -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]
+5 -5
View File
@@ -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 () => {
+3 -3
View File
@@ -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([]);
+1 -1
View File
@@ -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<string, unknown> = {};