Skip to content

Eliminate spurious TAG (TODO) outputs after multi-line HTML comment#913

Open
quidscio wants to merge 1 commit into
Gruntfuggly:masterfrom
quidscio:feature/MultilineHtmlComment
Open

Eliminate spurious TAG (TODO) outputs after multi-line HTML comment#913
quidscio wants to merge 1 commit into
Gruntfuggly:masterfrom
quidscio:feature/MultilineHtmlComment

Conversation

@quidscio

@quidscio quidscio commented Dec 7, 2025

Copy link
Copy Markdown

Identified whitespace pattern modification for HTML multi-line comment compatibility

This PR offers an amended regex to eliminate a extra TODO triggered by a multi-line HTML comment.

The PR also includes an updated test/tests.js to verify original vs updated behavior.

Summary

  • Replace the default regex’s trailing \s* with [ \t]* so multiline HTML comment openers can’t consume the newline before the real TODO, preventing ghost matches.
  • Mirror that regex change everywhere it’s user-facing (package defaults, markdown auto-update logic, README guidance) so all entry points are consistent.
  • Add a regression test in test/tests.js that reproduces the markdown snippet from the issue, proving the opener line no longer produces an extra TODO, and refresh the assertions to check line positions/strings.
  • Swap the deprecated substr usage in the test for slice to keep the suite compatible with modern TypeScript definitions.

Before view:

VSCode tree output before the update

Updated view:

VSCode tree output after change to default regex

Testcase (text in MD file):

TODO case 1 Shows up normally 
<!-- TODO case 2 Shows up normally -->

<!-- 
TODO case 3 NOT Preceded by extra TODO after multi-line HTML command
TODO case 10 Shows up normally 
-->

Fix to eliminate unwanted TODO

Change the end-of-line \s* to [ \t]*.

\s includes newlines.
When it found <!--, the \s* pattern matched the newline and whitespace, then found TODO on the next line, and treated it like a single match.

Changing \s* to [ \t]* restricts the whitespace matching to only spaces and tabs (no newlines).
This ensures TODO items must appear on the same line as their comment marker, preventing false matches when an HTML comment opener appears alone on a line above actual TODO text.

The old and updated regex are:

Initial: (//|#|<!--|;|/\*|^|^[ \t]*(-|\*|\d+.))\s*($TAGS)
Updated: (//|#|<!--|;|/\*|^|^[ \t]*(-|\*|\d+.))[ \t]*($TAGS) 

Testing

  • npm test
> npm test
> todo-tree@0.0.224 test
> qunit
TAP version 13
[clipped]
1..57
# pass 57
# skip 0
# todo 0
# fail 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant