From 6b33749efc652b1c6667f0706b2e191c777c57a5 Mon Sep 17 00:00:00 2001 From: Mike Busyrev Date: Sat, 3 Feb 2018 20:02:29 +0300 Subject: [PATCH 1/5] ability to specify error codes to //@ts-ignore --- src/compiler/program.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 24a1a0eb106b3..9666538391689 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3,7 +3,7 @@ /// namespace ts { - const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?)/; + const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+),\s*)*(?:TS\d+)?))?)/; export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined { return forEachAncestorDirectory(searchPath, ancestor => { @@ -1323,7 +1323,12 @@ namespace ts { } if (result[3]) { // @ts-ignore - return false; + const ignoreOptions = result[4]; + if (ignoreOptions) { + return ignoreOptions.indexOf('TS'+diagnostic.code) === -1; + } else { + return false; + } } line--; } From 8b95119a3d4f77b22ddec0a17217f5c1c94afaab Mon Sep 17 00:00:00 2001 From: Mike Busyrev Date: Sat, 3 Feb 2018 21:14:13 +0300 Subject: [PATCH 2/5] tests for ignoring specified errors --- .../checkJsFiles_skipDiagnostics.errors.txt | 43 +++++++++++++++++++ .../checkJsFiles_skipDiagnostics.symbols | 12 ++++++ .../checkJsFiles_skipDiagnostics.types | 15 +++++++ .../compiler/checkJsFiles_skipDiagnostics.ts | 9 ++++ 4 files changed, 79 insertions(+) create mode 100644 tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt b/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt new file mode 100644 index 0000000000000..543b226beec59 --- /dev/null +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt @@ -0,0 +1,43 @@ +tests/cases/compiler/a.js(37,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures. + + +==== tests/cases/compiler/a.js (1 errors) ==== + var x = 0; + + + /// @ts-ignore + x(); + + /// @ts-ignore + x(); + + /// @ts-ignore + x( + 2, + 3); + + + + // @ts-ignore + // come comment + // some other comment + + // @anohter + + x(); + + + + // @ts-ignore: no call signature + x(); + + // @ts-ignore TS2349 + x(); + + // @ts-ignore TS2349, TS2350 + x(); + + // @ts-ignore TS2350 here should be error + x(); + ~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures. \ No newline at end of file diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols b/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols index 5d9aa8c53c563..873d881467aa7 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols @@ -35,3 +35,15 @@ x(); x(); >x : Symbol(x, Decl(a.js, 0, 3)) +// @ts-ignore TS2349 +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2349, TS2350 +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2350 here should be error +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.types b/tests/baselines/reference/checkJsFiles_skipDiagnostics.types index a07bf43901b32..be8495529f279 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.types +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.types @@ -44,3 +44,18 @@ x(); >x() : any >x : number +// @ts-ignore TS2349 +x(); +>x() : any +>x : number + +// @ts-ignore TS2349, TS2350 +x(); +>x() : any +>x : number + +// @ts-ignore TS2350 here should be error +x(); +>x() : any +>x : number + diff --git a/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts b/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts index 48364c6a592ec..5a3a83b9d87d3 100644 --- a/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts +++ b/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts @@ -30,4 +30,13 @@ x(); // @ts-ignore: no call signature +x(); + +// @ts-ignore TS2349 +x(); + +// @ts-ignore TS2349, TS2350 +x(); + +// @ts-ignore TS2350 here should be error x(); \ No newline at end of file From 3a3ebb0a090b26044cd3c903dc9d79be38e60687 Mon Sep 17 00:00:00 2001 From: Mike Busyrev Date: Sat, 3 Feb 2018 21:54:41 +0300 Subject: [PATCH 3/5] fixing linting issues --- src/compiler/program.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9666538391689..f10657e893202 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1110,7 +1110,7 @@ namespace ts { // otherwise, using options specified in '--lib' instead of '--target' default library file const equalityComparer = host.useCaseSensitiveFileNames() ? equateStringsCaseSensitive : equateStringsCaseInsensitive; if (!options.lib) { - return equalityComparer(file.fileName, getDefaultLibraryFileName()); + return equalityComparer(file.fileName, getDefaultLibraryFileName()); } else { return forEach(options.lib, libFileName => equalityComparer(file.fileName, combinePaths(defaultLibraryPath, libFileName))); @@ -1325,10 +1325,9 @@ namespace ts { // @ts-ignore const ignoreOptions = result[4]; if (ignoreOptions) { - return ignoreOptions.indexOf('TS'+diagnostic.code) === -1; - } else { - return false; + return ignoreOptions.indexOf("TS" + diagnostic.code) === -1; } + return false; } line--; } From fd067ee7b63fd7360ce1a90e98a34d1cb0ec2f1e Mon Sep 17 00:00:00 2001 From: Mike Busyrev Date: Mon, 5 Feb 2018 10:53:49 +0300 Subject: [PATCH 4/5] removed redundant grouping and ? in ignoreDiagnosticCommentRegEx --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f10657e893202..2123c4e9990e9 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3,7 +3,7 @@ /// namespace ts { - const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+),\s*)*(?:TS\d+)?))?)/; + const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+),\s*)*TS\d+))?)/; export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined { return forEachAncestorDirectory(searchPath, ancestor => { From 23ca2bea1102ea65d5594b15ac7af10b14d31335 Mon Sep 17 00:00:00 2001 From: Mike Busyrev Date: Thu, 15 Feb 2018 21:04:31 +0300 Subject: [PATCH 5/5] added support for spaces before comma, more strict error code detection --- src/compiler/program.ts | 5 +++-- .../reference/checkJsFiles_skipDiagnostics.errors.txt | 8 +++++++- .../reference/checkJsFiles_skipDiagnostics.symbols | 8 ++++++++ .../reference/checkJsFiles_skipDiagnostics.types | 10 ++++++++++ tests/cases/compiler/checkJsFiles_skipDiagnostics.ts | 6 ++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2123c4e9990e9..cb43475ffdd29 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3,7 +3,7 @@ /// namespace ts { - const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+),\s*)*TS\d+))?)/; + const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+)\s*,\s*)*TS\d+))?)/; export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined { return forEachAncestorDirectory(searchPath, ancestor => { @@ -1325,7 +1325,8 @@ namespace ts { // @ts-ignore const ignoreOptions = result[4]; if (ignoreOptions) { - return ignoreOptions.indexOf("TS" + diagnostic.code) === -1; + const errorCodes = ignoreOptions.split(/\s*,\s*/g); + return errorCodes.indexOf("TS" + diagnostic.code) === -1; } return false; } diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt b/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt index 543b226beec59..2b3461bab2b5f 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/a.js(37,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures. +tests/cases/compiler/a.js(43,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures. ==== tests/cases/compiler/a.js (1 errors) ==== @@ -37,6 +37,12 @@ tests/cases/compiler/a.js(37,1): error TS2349: Cannot invoke an expression whose // @ts-ignore TS2349, TS2350 x(); + // @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment + x(); + + // @ts-ignore TS2349 , TS2350, // trailing comma + x(); + // @ts-ignore TS2350 here should be error x(); ~~~ diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols b/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols index 873d881467aa7..5c10b6a9fd753 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols @@ -43,6 +43,14 @@ x(); x(); >x : Symbol(x, Decl(a.js, 0, 3)) +// @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2349 , TS2350, // trailing comma +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + // @ts-ignore TS2350 here should be error x(); >x : Symbol(x, Decl(a.js, 0, 3)) diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.types b/tests/baselines/reference/checkJsFiles_skipDiagnostics.types index be8495529f279..d5da5e760ea6c 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.types +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.types @@ -54,6 +54,16 @@ x(); >x() : any >x : number +// @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment +x(); +>x() : any +>x : number + +// @ts-ignore TS2349 , TS2350, // trailing comma +x(); +>x() : any +>x : number + // @ts-ignore TS2350 here should be error x(); >x() : any diff --git a/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts b/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts index 5a3a83b9d87d3..7c15563e19af0 100644 --- a/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts +++ b/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts @@ -38,5 +38,11 @@ x(); // @ts-ignore TS2349, TS2350 x(); +// @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment +x(); + +// @ts-ignore TS2349 , TS2350, // trailing comma +x(); + // @ts-ignore TS2350 here should be error x(); \ No newline at end of file