Skip to content

Commit

Permalink
Ignore colons (fix #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Mar 13, 2024
1 parent 9fe36ad commit e83185a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions samples/1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function add(foo: any, bar: any): any { // todo@types
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;
}

Expand All @@ -24,12 +24,12 @@ function greet2(name: string) { // todo1 add return typehint
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('foo'); // todo

// todo generic todo 2
// todo: generic todo 2
// TODO: generic todo 3
// todo11 invalid todo
1 change: 1 addition & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def

- abc
- todo0 def
- todo00: ghi
- [ ] bar
- [ ] baz

Expand Down
2 changes: 1 addition & 1 deletion samples/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- todo00 priority bar

## High priority
- todo0 a
- todo0: a
- foo
- [ ] bar

Expand Down
31 changes: 21 additions & 10 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
continue;
}

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

word = word.trim_end_matches(':');

// Handles: `todo`, `TODO`, `todo:`, `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 {
text: text.to_string(),
location: Location {
Expand Down Expand Up @@ -289,8 +291,8 @@ pub fn scan_todo_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
}

for word in line.split_whitespace() {
if word.to_lowercase().starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
if let Some(priority) = parse_priority(word) {
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.trim_end_matches(':')) {
entries.push(Entry {
text: clean_line(line, word).to_string(),
location: Location {
Expand Down Expand Up @@ -360,8 +362,8 @@ pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()>
}

for word in line.split_whitespace() {
if word.to_lowercase().starts_with("todo") && word.chars().any(|ch| PRIORITY_CHARS.contains(&ch)) {
if let Some(priority) = parse_priority(word) {
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.trim_end_matches(':')) {
entries.push(Entry {
text: clean_line(line, word).to_string(),
location: Location {
Expand Down Expand Up @@ -926,7 +928,7 @@ mod tests {

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

assert_eq!(4, entries.len());
assert_eq!(5, entries.len());

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

assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("bar"),
data: EntryData::Priority(-1),
text: String::from("ghi"),
location: Location {
file: path.clone(),
line: 21,
Expand All @@ -957,11 +959,20 @@ mod tests {

assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("baz"),
text: String::from("bar"),
location: Location {
file: path.clone(),
line: 22,
}
}, entries[3]);

assert_eq!(Entry {
data: EntryData::Generic,
text: String::from("baz"),
location: Location {
file: path.clone(),
line: 23,
}
}, entries[4]);
}
}

0 comments on commit e83185a

Please sign in to comment.