From 6f28f83f18de7519b1ea8a13284f469c8e6870eb Mon Sep 17 00:00:00 2001 From: Armando Aguirre Date: Mon, 17 Jul 2017 17:35:46 -0700 Subject: [PATCH 1/2] Added node_modules path check on getTodoComments method. --- src/services/services.ts | 8 +++++++- tests/cases/fourslash/todoComments18.ts | 6 ++++++ tests/cases/fourslash/todoComments19.ts | 6 ++++++ tests/cases/fourslash/todoComments20.ts | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/todoComments18.ts create mode 100644 tests/cases/fourslash/todoComments19.ts create mode 100644 tests/cases/fourslash/todoComments20.ts diff --git a/src/services/services.ts b/src/services/services.ts index 30c6b88b1e2..e6e4f755ab3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1834,7 +1834,7 @@ namespace ts { const fileContents = sourceFile.text; const result: TodoComment[] = []; - if (descriptors.length > 0) { + if (descriptors.length > 0 && !isNodeModulesFile(fileName)) { const regExp = getTodoCommentsRegExp(); let matchArray: RegExpExecArray; @@ -1958,6 +1958,12 @@ namespace ts { (char >= CharacterCodes.A && char <= CharacterCodes.Z) || (char >= CharacterCodes._0 && char <= CharacterCodes._9); } + + function isNodeModulesFile(path: string): boolean { + const node_modulesFolderName = "/node_modules/"; + + return path.indexOf(node_modulesFolderName) !== -1; + } } function getRenameInfo(fileName: string, position: number): RenameInfo { diff --git a/tests/cases/fourslash/todoComments18.ts b/tests/cases/fourslash/todoComments18.ts new file mode 100644 index 00000000000..ded5ad70d42 --- /dev/null +++ b/tests/cases/fourslash/todoComments18.ts @@ -0,0 +1,6 @@ +// Tests node_modules name in file still gets todos. + +// @Filename: /node_modules_todotest0.ts +//// // [|TODO|] + +verify.todoCommentsInCurrentFile(["TODO"]); \ No newline at end of file diff --git a/tests/cases/fourslash/todoComments19.ts b/tests/cases/fourslash/todoComments19.ts new file mode 100644 index 00000000000..94239ba7dc7 --- /dev/null +++ b/tests/cases/fourslash/todoComments19.ts @@ -0,0 +1,6 @@ +// Tests that todos are not found in node_modules folder. + +// @Filename: /node_modules/todotest0.ts +//// // TODO + +verify.todoCommentsInCurrentFile(["TODO"]); diff --git a/tests/cases/fourslash/todoComments20.ts b/tests/cases/fourslash/todoComments20.ts new file mode 100644 index 00000000000..cc66d278fa8 --- /dev/null +++ b/tests/cases/fourslash/todoComments20.ts @@ -0,0 +1,4 @@ +// @Filename: dir1/node_modules/todotest0.ts +//// // TODO + +verify.todoCommentsInCurrentFile(["TODO"]); From 9bdd17e842ed39b4a5d6b8a6b48053b6b55abd51 Mon Sep 17 00:00:00 2001 From: Armando Aguirre Date: Wed, 19 Jul 2017 15:42:01 -0700 Subject: [PATCH 2/2] Added explanation comment for excluding files. --- src/services/services.ts | 3 ++- tests/cases/fourslash/todoComments18.ts | 4 +++- tests/cases/fourslash/todoComments19.ts | 7 ++++++- tests/cases/fourslash/todoComments20.ts | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index e6e4f755ab3..78003351a57 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1834,7 +1834,8 @@ namespace ts { const fileContents = sourceFile.text; const result: TodoComment[] = []; - if (descriptors.length > 0 && !isNodeModulesFile(fileName)) { + // Exclude node_modules files as we don't want to show the todos of external libraries. + if (descriptors.length > 0 && !isNodeModulesFile(sourceFile.fileName)) { const regExp = getTodoCommentsRegExp(); let matchArray: RegExpExecArray; diff --git a/tests/cases/fourslash/todoComments18.ts b/tests/cases/fourslash/todoComments18.ts index ded5ad70d42..d591f98236f 100644 --- a/tests/cases/fourslash/todoComments18.ts +++ b/tests/cases/fourslash/todoComments18.ts @@ -1,6 +1,8 @@ +/// + // Tests node_modules name in file still gets todos. -// @Filename: /node_modules_todotest0.ts +// @Filename: /node_modules_todoTest0.ts //// // [|TODO|] verify.todoCommentsInCurrentFile(["TODO"]); \ No newline at end of file diff --git a/tests/cases/fourslash/todoComments19.ts b/tests/cases/fourslash/todoComments19.ts index 94239ba7dc7..2f14ba69a57 100644 --- a/tests/cases/fourslash/todoComments19.ts +++ b/tests/cases/fourslash/todoComments19.ts @@ -1,6 +1,11 @@ +/// + // Tests that todos are not found in node_modules folder. -// @Filename: /node_modules/todotest0.ts +// @Filename: todoTest0.ts +//// import * as foo1 from "fake-module"; + +// @Filename: node_modules/fake-module/ts.ts //// // TODO verify.todoCommentsInCurrentFile(["TODO"]); diff --git a/tests/cases/fourslash/todoComments20.ts b/tests/cases/fourslash/todoComments20.ts index cc66d278fa8..2284236714d 100644 --- a/tests/cases/fourslash/todoComments20.ts +++ b/tests/cases/fourslash/todoComments20.ts @@ -1,4 +1,6 @@ -// @Filename: dir1/node_modules/todotest0.ts +/// + +// @Filename: dir1/node_modules/todoTest0.ts //// // TODO verify.todoCommentsInCurrentFile(["TODO"]);