Skip to content

Commit e83185a

Browse files
committed
Ignore colons (fix #2)
1 parent 9fe36ad commit e83185a

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

samples/1.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function add(foo: any, bar: any): any { // todo@types
22
return foo + bar;
33
}
44

5-
function subtract(foo: any, bar: any): any { // todo@types add types
5+
function subtract(foo: any, bar: any): any { // todo@types: add types
66
return foo - bar;
77
}
88

@@ -24,12 +24,12 @@ function greet2(name: string) { // todo1 add return typehint
2424
console.log(`Hello ${name}`);
2525
}
2626

27-
function echo(str: string) { // todo2 add return typehint
27+
function echo(str: string) { // todo2: add return typehint
2828
console.log(str);
2929
}
3030

3131
// console.log('foo'); // todo
3232

33-
// todo generic todo 2
33+
// todo: generic todo 2
3434
// TODO: generic todo 3
3535
// todo11 invalid todo

samples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def
1818

1919
- abc
2020
- todo0 def
21+
- todo00: ghi
2122
- [ ] bar
2223
- [ ] baz
2324

samples/todo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- todo00 priority bar
44

55
## High priority
6-
- todo0 a
6+
- todo0: a
77
- foo
88
- [ ] bar
99

src/scan.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
148148
continue;
149149
}
150150

151-
for word in line.split_whitespace() {
151+
for mut word in line.split_whitespace() {
152152
if ! word.to_lowercase().starts_with("todo") {
153153
continue;
154154
}
@@ -168,9 +168,11 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
168168
break;
169169
}
170170

171+
word = word.trim_end_matches(':');
172+
171173
// Handles: `todo`, `TODO`, `todo:`, `TODO:`
172174
// Also trims `"` and `'` to handle cases like `foo="bar todo"`
173-
if word.to_lowercase().trim_end_matches(':').trim_end_matches('"').trim_end_matches('\'') == "todo" {
175+
if word.to_lowercase().trim_end_matches('"').trim_end_matches('\'') == "todo" {
174176
entries.push(Entry {
175177
text: text.to_string(),
176178
location: Location {
@@ -289,8 +291,8 @@ pub fn scan_todo_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
289291
}
290292

291293
for word in line.split_whitespace() {
292-
if word.to_lowercase().starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
293-
if let Some(priority) = parse_priority(word) {
294+
if word.to_lowercase().trim_end_matches(':').starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
295+
if let Some(priority) = parse_priority(word.trim_end_matches(':')) {
294296
entries.push(Entry {
295297
text: clean_line(line, word).to_string(),
296298
location: Location {
@@ -360,8 +362,8 @@ pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()>
360362
}
361363

362364
for word in line.split_whitespace() {
363-
if word.to_lowercase().starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
364-
if let Some(priority) = parse_priority(word) {
365+
if word.to_lowercase().trim_end_matches(':').starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
366+
if let Some(priority) = parse_priority(word.trim_end_matches(':')) {
365367
entries.push(Entry {
366368
text: clean_line(line, word).to_string(),
367369
location: Location {
@@ -926,7 +928,7 @@ mod tests {
926928

927929
scan_readme_file(path.as_path(), &mut entries).unwrap();
928930

929-
assert_eq!(4, entries.len());
931+
assert_eq!(5, entries.len());
930932

931933
assert_eq!(Entry {
932934
data: EntryData::Generic,
@@ -947,8 +949,8 @@ mod tests {
947949
}, entries[1]);
948950

949951
assert_eq!(Entry {
950-
data: EntryData::Generic,
951-
text: String::from("bar"),
952+
data: EntryData::Priority(-1),
953+
text: String::from("ghi"),
952954
location: Location {
953955
file: path.clone(),
954956
line: 21,
@@ -957,11 +959,20 @@ mod tests {
957959

958960
assert_eq!(Entry {
959961
data: EntryData::Generic,
960-
text: String::from("baz"),
962+
text: String::from("bar"),
961963
location: Location {
962964
file: path.clone(),
963965
line: 22,
964966
}
965967
}, entries[3]);
968+
969+
assert_eq!(Entry {
970+
data: EntryData::Generic,
971+
text: String::from("baz"),
972+
location: Location {
973+
file: path.clone(),
974+
line: 23,
975+
}
976+
}, entries[4]);
966977
}
967978
}

0 commit comments

Comments
 (0)