Skip to content

Commit fe86d2f

Browse files
author
Armando Aguirre
authored
Merge pull request #17257 from armanio123/FixNodeModulesTodos
Added node_modules path check on getTodoComments method.
2 parents 8fa1d2e + 9bdd17e commit fe86d2f

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/services/services.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,8 @@ namespace ts {
18341834
const fileContents = sourceFile.text;
18351835
const result: TodoComment[] = [];
18361836

1837-
if (descriptors.length > 0) {
1837+
// Exclude node_modules files as we don't want to show the todos of external libraries.
1838+
if (descriptors.length > 0 && !isNodeModulesFile(sourceFile.fileName)) {
18381839
const regExp = getTodoCommentsRegExp();
18391840

18401841
let matchArray: RegExpExecArray;
@@ -1958,6 +1959,12 @@ namespace ts {
19581959
(char >= CharacterCodes.A && char <= CharacterCodes.Z) ||
19591960
(char >= CharacterCodes._0 && char <= CharacterCodes._9);
19601961
}
1962+
1963+
function isNodeModulesFile(path: string): boolean {
1964+
const node_modulesFolderName = "/node_modules/";
1965+
1966+
return path.indexOf(node_modulesFolderName) !== -1;
1967+
}
19611968
}
19621969

19631970
function getRenameInfo(fileName: string, position: number): RenameInfo {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Tests node_modules name in file still gets todos.
4+
5+
// @Filename: /node_modules_todoTest0.ts
6+
//// // [|TODO|]
7+
8+
verify.todoCommentsInCurrentFile(["TODO"]);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Tests that todos are not found in node_modules folder.
4+
5+
// @Filename: todoTest0.ts
6+
//// import * as foo1 from "fake-module";
7+
8+
// @Filename: node_modules/fake-module/ts.ts
9+
//// // TODO
10+
11+
verify.todoCommentsInCurrentFile(["TODO"]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: dir1/node_modules/todoTest0.ts
4+
//// // TODO
5+
6+
verify.todoCommentsInCurrentFile(["TODO"]);

0 commit comments

Comments
 (0)