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:
parent
fa9c36bf6d
commit
6665e369bf
2 changed files with 26 additions and 16 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "todos"
|
name = "todos"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
authors = ["Samuel Štancl <samuel@archte.ch>"]
|
authors = ["Samuel Štancl <samuel@archte.ch>"]
|
||||||
description = "An intuitive system for organizing TODOs in code"
|
description = "An intuitive system for organizing TODOs in code"
|
||||||
|
|
||||||
|
|
|
||||||
40
src/scan.rs
40
src/scan.rs
|
|
@ -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>) {
|
pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
|
||||||
for (line_num, line) in str.lines().enumerate() {
|
for (line_num, line) in str.lines().enumerate() {
|
||||||
if ! line.to_lowercase().contains("todo") {
|
if let Some(i) = line.to_lowercase().find("todo")
|
||||||
continue;
|
&& line[i - 1..i + 4].trim_start().len() == 4
|
||||||
}
|
{
|
||||||
|
let mut word = line[i..]
|
||||||
for mut word in line.split_whitespace() {
|
.split_whitespace()
|
||||||
if ! word.to_lowercase().starts_with("todo") {
|
.next()
|
||||||
continue;
|
.expect("Prior condition should enforce we have a word starting at this position");
|
||||||
}
|
|
||||||
|
|
||||||
let text = clean_line(line, word);
|
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,
|
data: EntryData::Generic,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
word = word.trim_end_matches(':');
|
word = word.trim_end_matches(':');
|
||||||
|
|
@ -199,12 +198,10 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
|
||||||
data: EntryData::Generic,
|
data: EntryData::Generic,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if word.contains('@') {
|
if let Some((_todo, category)) = word.split_once('@') {
|
||||||
let category = word.split('@').nth(1).unwrap();
|
|
||||||
|
|
||||||
entries.push(Entry {
|
entries.push(Entry {
|
||||||
text: text.to_string(),
|
text: text.to_string(),
|
||||||
location: Location {
|
location: Location {
|
||||||
|
|
@ -214,7 +211,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
|
||||||
data: EntryData::Category(category.to_string()),
|
data: EntryData::Category(category.to_string()),
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
|
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 */
|
||||||
// TODO@baz3 b
|
// TODO@baz3 b
|
||||||
<!-- TODO@baz3 -->
|
<!-- TODO@baz3 -->
|
||||||
|
// TODO@
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let mut entries: Vec<Entry> = vec![];
|
let mut entries: Vec<Entry> = vec![];
|
||||||
|
|
@ -614,6 +612,18 @@ mod tests {
|
||||||
line: 12,
|
line: 12,
|
||||||
}
|
}
|
||||||
}, entries[6]);
|
}, entries[6]);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Entry {
|
||||||
|
data: EntryData::Category(String::from("")),
|
||||||
|
text: String::from(""),
|
||||||
|
location: Location {
|
||||||
|
file: path.clone(),
|
||||||
|
line: 13,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
entries[7]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue