Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ You can also include and exclude folders from the tree using the context menu. T
When the extension was first written, very basic markdown support was added simply by adding a pattern to the default regex to match "`- [ ]`". A better way to handle markdown TODOs is to add "`(-|\d+.)`" to the list of "comments" in the first part of the regex and then adding "`[ ]`" and "`[x]`" to the list of tags in `settings.json`, e.g. :

```json
"todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^\\s*(-|\\d+.))\\s*($TAGS)"
"todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^\\s*(-|\\d+.))[ \t]*($TAGS)"
"todo-tree.general.tags": [
"BUG",
"HACK",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@
"type": "object",
"properties": {
"todo-tree.regex.regex": {
"default": "(//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)",
"default": "(//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))[ \t]*($TAGS)",
"markdownDescription": "%todo-tree.configuration.regex.regex.markdownDescription%",
"type": "string",
"minLength": 1,
Expand Down
2 changes: 1 addition & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ function activate( context )
ignoreMarkdownUpdate = true;
addTag( '[ ]' );
addTag( '[x]' );
c.update( 'regex.regex', '(//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)', true );
c.update( 'regex.regex', '(//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))[ \\t]*($TAGS)', true );
}
else if( button === MORE_INFO_BUTTON )
{
Expand Down
42 changes: 42 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,48 @@ QUnit.test( "utils.getRegexForRipGrep can remove the case insensitive flag", fun
assert.equal( utils.getRegexForRipGrep().flags, "gm" );
} );

QUnit.test( "default regex should not match TODOs after multiline HTML openers", function( assert )
{
var testConfig = stubs.getTestConfig();
testConfig.regexSource = "(//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))[ \\t]*($TAGS)";
utils.init( testConfig );

var regex = utils.getRegexForRipGrep();
var sample = [
"TODO case 1 Shows up normally",
"<!-- TODO case 2 Shows up normally -->",
"",
"<!--",
"TODO case 3 NOT Preceded by extra TODO after multi-line HTML comment",
"TODO case 4 Shows up normally",
"-->"
].join( "\n" );

var matches = Array.from( sample.matchAll( regex ) );
var lines = sample.split( "\n" );
var lineNumbers = matches.map( function( match )
{
var uptoMatch = sample.slice( 0, match.index );
return uptoMatch.split( "\n" ).length - 1;
} );
var matchedLines = lineNumbers.map( function( lineNumber )
{
return lines[ lineNumber ];
} );

assert.equal( matches.length, 4, "every actual TODO occurrence should still be detected" );
assert.equal( lineNumbers.indexOf( 3 ), -1, "regex should not report TODOs starting on a bare HTML opener line" );
assert.deepEqual( lineNumbers, [ 0, 1, 4, 5 ], "default regex should only match TODO tags on their own lines" );
assert.deepEqual( matchedLines,
[
"TODO case 1 Shows up normally",
"<!-- TODO case 2 Shows up normally -->",
"TODO case 3 NOT Preceded by extra TODO after multi-line HTML comment",
"TODO case 4 Shows up normally"
],
"default regex should only match TODO text which shares its line" );
} );

QUnit.test( "utils.isIncluded returns true when no includes or excludes are specified", function( assert )
{
assert.ok( utils.isIncluded( "filename.js", [], [] ) === true );
Expand Down