Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit 8c54859

Browse files
committed
ABC123 fix(refactor): Refactor build_todo_footer to be more idiomatic rust
TODO: - [ ] New features or bug fixes are covered by appropriate new tests.
1 parent 120ca58 commit 8c54859

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "check-commit"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
authors = ["Claes Adamsson <claes.adamsson@gmail.com>"]
55
repository = "https://github.com/cladam/check-commit"
66
readme="README.md"

src/main.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ fn run_checklist_interactive(checklist: &[String]) -> anyhow::Result<Vec<usize>>
3030
}
3131

3232
fn build_todo_footer(checklist: &[String], checked_indices: &[usize]) -> String {
33-
if checked_indices.len() == checklist.len() {
34-
return String::new();
33+
//let checked_indices: Vec<usize> = checked_indices.iter().cloned().collect();
34+
let unchecked_items: Vec<String> = checklist
35+
.iter()
36+
.enumerate()
37+
.filter(|(i, _)| !checked_indices.contains(&i))
38+
.map(|(_, item)| format!("- [ ] {}", item))
39+
//.filter_map(|(i, item)| if !checked_indices.contains(&i) { Some(item.clone()) } else { None })
40+
.collect();
41+
if unchecked_items.is_empty() {
42+
String::new()
43+
} else {
44+
format!("\n\nTODO:\n{}", unchecked_items.join("\n"))
3545
}
36-
let mut footer = String::from("\nTODO:\n");
37-
for (i, item) in checklist.iter().enumerate() {
38-
if !checked_indices.contains(&i) {
39-
footer.push_str(&format!("- [ ] {}\n", item));
40-
}
41-
}
42-
footer
4346
}
4447

4548
fn main() -> anyhow::Result<()> {

0 commit comments

Comments
 (0)