Qlty config and code cleanup !1

merged merged by cmc on 2026-10-30 06:04 UTC · cmc/learn:cleanup into main

3 files changed, +94 −39

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +46
@@ -0,0 +1,46 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14]
15
16test_patterns = [
17 "**/test/**",
18 "**/tests/**",
19 "**/Tests/**",
20 "**/*_test.*",
21 "**/test_*.*",
22 "**/*.test.*",
23 "**/*Tests.swift",
24 "e2e/**",
25]
26
27[[source]]
28name = "default"
29default = true
30
31[[plugin]]
32name = "osv-scanner"
33
34[[plugin]]
35name = "trufflehog"
36
37# Early returns are guard clauses, which keep the happy path unindented.
38[smells.return_statements]
39enabled = false
40
41# Function and file complexity are left to review rather than counted.
42[smells.function_complexity]
43enabled = false
44
45[smells.file_complexity]
46enabled = false
rust/todo/src/main.rs +41 −39
@@ -41,56 +41,58 @@ fn main() {
41 41
42 let file_path = "tasks.txt"; 42 let file_path = "tasks.txt";
43 43
44 // Handle task completion
45 if let Some(ids) = matches.get_many::<String>("done") { 44 if let Some(ids) = matches.get_many::<String>("done") {
46 let mut tasks = load_tasks(file_path); 45 mark_done(file_path, ids);
47 let mut completed_tasks = Vec::new(); 46 }
48 for id in ids {
49 if let Ok(index) = id.parse::<usize>() {
50 if index > 0 && index <= tasks.len() {
51 tasks[index - 1].completed = true; // Mark task as complete
52 } else {
53 completed_tasks.push(id.clone()); // Collect invalid task IDs
54 }
55 }
56 }
57 save_tasks(file_path, &tasks);
58 47
59 // Alert for nonexistent tasks 48 if let Some(new_tasks) = matches.get_many::<String>("task") {
60 if !completed_tasks.is_empty() { 49 add_tasks(file_path, new_tasks);
61 for id in completed_tasks { 50 }
62 println!("Task {} doesn't exist.", id);
63 }
64 } else {
65 println!("Tasks marked as complete.");
66 }
67 51
68 // Display the updated task list 52 // Display saved tasks if no new tasks or done tasks were provided
53 if !matches.contains_id("task") && !matches.contains_id("done") {
69 display_tasks(file_path); 54 display_tasks(file_path);
70 } 55 }
56}
71 57
72 // Handle new tasks 58fn mark_done<'a>(file_path: &str, ids: impl Iterator<Item = &'a String>) {
73 if let Some(new_tasks) = matches.get_many::<String>("task") { 59 let mut tasks = load_tasks(file_path);
74 let mut tasks = load_tasks(file_path); 60 let mut missing = Vec::new();
75 let next_id = tasks.len() + 1; // Determine the next task ID 61 for id in ids {
76 for task_desc in new_tasks { 62 if let Ok(index) = id.parse::<usize>() {
77 tasks.push(Task { 63 if index > 0 && index <= tasks.len() {
78 id: next_id, 64 tasks[index - 1].completed = true;
79 description: task_desc.to_string(), 65 } else {
80 completed: false, 66 missing.push(id.clone());
81 }); 67 }
82 } 68 }
83 save_tasks(file_path, &tasks); 69 }
84 println!("Tasks saved to {}", file_path); 70 save_tasks(file_path, &tasks);
85 71
86 // Display the updated task list 72 if missing.is_empty() {
87 display_tasks(file_path); 73 println!("Tasks marked as complete.");
74 }
75 for id in missing {
76 println!("Task {} doesn't exist.", id);
88 } 77 }
89 78
90 // Display saved tasks if no new tasks or done tasks were provided 79 display_tasks(file_path);
91 if !matches.contains_id("task") && !matches.contains_id("done") { 80}
92 display_tasks(file_path); 81
82fn add_tasks<'a>(file_path: &str, new_tasks: impl Iterator<Item = &'a String>) {
83 let mut tasks = load_tasks(file_path);
84 let next_id = tasks.len() + 1;
85 for task_desc in new_tasks {
86 tasks.push(Task {
87 id: next_id,
88 description: task_desc.to_string(),
89 completed: false,
90 });
93 } 91 }
92 save_tasks(file_path, &tasks);
93 println!("Tasks saved to {}", file_path);
94
95 display_tasks(file_path);
94} 96}
95 97
96fn load_tasks(file_path: &str) -> Vec<Task> { 98fn load_tasks(file_path: &str) -> Vec<Task> {