1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2026-08-06 04:24:04 +00:00

Improve some readability (and prevent some duplicate search within lines)

This commit is contained in:
Zykino 2026-07-30 00:24:42 +02:00
parent fa9c36bf6d
commit 6665e369bf
2 changed files with 26 additions and 16 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "todos"
version = "0.1.1"
edition = "2021"
edition = "2024"
authors = ["Samuel Štancl <samuel@archte.ch>"]
description = "An intuitive system for organizing TODOs in code"

View file

@ -161,14 +161,13 @@ pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec<Exclud
pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
for (line_num, line) in str.lines().enumerate() {
if ! line.to_lowercase().contains("todo") {
continue;
}
for mut word in line.split_whitespace() {
if ! word.to_lowercase().starts_with("todo") {
continue;
}
if let Some(i) = line.to_lowercase().find("todo")
&& line[i - 1..i + 4].trim_start().len() == 4
{
let mut word = line[i..]
.split_whitespace()
.next()
.expect("Prior condition should enforce we have a word starting at this position");
let text = clean_line(line, word);
@ -182,7 +181,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
data: EntryData::Generic,
});
break;
continue;
}
word = word.trim_end_matches(':');
@ -199,12 +198,10 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
data: EntryData::Generic,
});
break;
continue;
}
if word.contains('@') {
let category = word.split('@').nth(1).unwrap();
if let Some((_todo, category)) = word.split_once('@') {
entries.push(Entry {
text: text.to_string(),
location: Location {
@ -214,7 +211,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
data: EntryData::Category(category.to_string()),
});
break;
continue;
}
if word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
@ -229,7 +226,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
});
}
break;
continue;
}
}
}
@ -542,6 +539,7 @@ mod tests {
/* TODO@baz3 */
// TODO@baz3 b
<!-- TODO@baz3 -->
// TODO@
"#;
let mut entries: Vec<Entry> = vec![];
@ -614,6 +612,18 @@ mod tests {
line: 12,
}
}, entries[6]);
assert_eq!(
Entry {
data: EntryData::Category(String::from("")),
text: String::from(""),
location: Location {
file: path.clone(),
line: 13,
}
},
entries[7]
);
}
#[test]