1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2025-12-12 09:04:03 +00:00

Ignore colons (fix #2)

This commit is contained in:
Samuel Štancl 2024-03-13 20:35:48 +01:00
parent 9fe36adf20
commit e83185a687
4 changed files with 26 additions and 14 deletions

View file

@ -2,7 +2,7 @@ function add(foo: any, bar: any): any { // todo@types
return foo + bar; return foo + bar;
} }
function subtract(foo: any, bar: any): any { // todo@types add types function subtract(foo: any, bar: any): any { // todo@types: add types
return foo - bar; return foo - bar;
} }
@ -24,12 +24,12 @@ function greet2(name: string) { // todo1 add return typehint
console.log(`Hello ${name}`); console.log(`Hello ${name}`);
} }
function echo(str: string) { // todo2 add return typehint function echo(str: string) { // todo2: add return typehint
console.log(str); console.log(str);
} }
// console.log('foo'); // todo // console.log('foo'); // todo
// todo generic todo 2 // todo: generic todo 2
// TODO: generic todo 3 // TODO: generic todo 3
// todo11 invalid todo // todo11 invalid todo

View file

@ -18,6 +18,7 @@ def
- abc - abc
- todo0 def - todo0 def
- todo00: ghi
- [ ] bar - [ ] bar
- [ ] baz - [ ] baz

View file

@ -3,7 +3,7 @@
- todo00 priority bar - todo00 priority bar
## High priority ## High priority
- todo0 a - todo0: a
- foo - foo
- [ ] bar - [ ] bar

View file

@ -148,7 +148,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
continue; continue;
} }
for word in line.split_whitespace() { for mut word in line.split_whitespace() {
if ! word.to_lowercase().starts_with("todo") { if ! word.to_lowercase().starts_with("todo") {
continue; continue;
} }
@ -168,9 +168,11 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
break; break;
} }
word = word.trim_end_matches(':');
// Handles: `todo`, `TODO`, `todo:`, `TODO:` // Handles: `todo`, `TODO`, `todo:`, `TODO:`
// Also trims `"` and `'` to handle cases like `foo="bar todo"` // Also trims `"` and `'` to handle cases like `foo="bar todo"`
if word.to_lowercase().trim_end_matches(':').trim_end_matches('"').trim_end_matches('\'') == "todo" { if word.to_lowercase().trim_end_matches('"').trim_end_matches('\'') == "todo" {
entries.push(Entry { entries.push(Entry {
text: text.to_string(), text: text.to_string(),
location: Location { location: Location {
@ -289,8 +291,8 @@ pub fn scan_todo_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
} }
for word in line.split_whitespace() { for word in line.split_whitespace() {
if word.to_lowercase().starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) { if word.to_lowercase().trim_end_matches(':').starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
if let Some(priority) = parse_priority(word) { if let Some(priority) = parse_priority(word.trim_end_matches(':')) {
entries.push(Entry { entries.push(Entry {
text: clean_line(line, word).to_string(), text: clean_line(line, word).to_string(),
location: Location { location: Location {
@ -360,8 +362,8 @@ pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()>
} }
for word in line.split_whitespace() { for word in line.split_whitespace() {
if word.to_lowercase().starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) { if word.to_lowercase().trim_end_matches(':').starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
if let Some(priority) = parse_priority(word) { if let Some(priority) = parse_priority(word.trim_end_matches(':')) {
entries.push(Entry { entries.push(Entry {
text: clean_line(line, word).to_string(), text: clean_line(line, word).to_string(),
location: Location { location: Location {
@ -926,7 +928,7 @@ mod tests {
scan_readme_file(path.as_path(), &mut entries).unwrap(); scan_readme_file(path.as_path(), &mut entries).unwrap();
assert_eq!(4, entries.len()); assert_eq!(5, entries.len());
assert_eq!(Entry { assert_eq!(Entry {
data: EntryData::Generic, data: EntryData::Generic,
@ -947,8 +949,8 @@ mod tests {
}, entries[1]); }, entries[1]);
assert_eq!(Entry { assert_eq!(Entry {
data: EntryData::Generic, data: EntryData::Priority(-1),
text: String::from("bar"), text: String::from("ghi"),
location: Location { location: Location {
file: path.clone(), file: path.clone(),
line: 21, line: 21,
@ -957,11 +959,20 @@ mod tests {
assert_eq!(Entry { assert_eq!(Entry {
data: EntryData::Generic, data: EntryData::Generic,
text: String::from("baz"), text: String::from("bar"),
location: Location { location: Location {
file: path.clone(), file: path.clone(),
line: 22, line: 22,
} }
}, entries[3]); }, entries[3]);
assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("baz"),
location: Location {
file: path.clone(),
line: 23,
}
}, entries[4]);
} }
} }