Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore specified error in //@ts-ignore #21602

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 7 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <reference path="core.ts" />

namespace ts {
const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?)/;
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 => {
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -1323,6 +1323,11 @@ namespace ts {
}
if (result[3]) {
// @ts-ignore
const ignoreOptions = result[4];
if (ignoreOptions) {
const errorCodes = ignoreOptions.split(/\s*,\s*/g);
return errorCodes.indexOf("TS" + diagnostic.code) === -1;
}
return false;
}
line--;
Expand Down
49 changes: 49 additions & 0 deletions tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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) ====
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 TS2349 , TS2350 // space before comma and additioanl comment
x();

// @ts-ignore TS2349 , TS2350, // trailing comma
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.
20 changes: 20 additions & 0 deletions tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,23 @@ 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 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))

25 changes: 25 additions & 0 deletions tests/baselines/reference/checkJsFiles_skipDiagnostics.types
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,28 @@ x();
>x() : any
>x : number

// @ts-ignore TS2349
x();
>x() : any
>x : number

// @ts-ignore TS2349, TS2350
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
>x : number

15 changes: 15 additions & 0 deletions tests/cases/compiler/checkJsFiles_skipDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ x();


// @ts-ignore: no call signature
x();

// @ts-ignore TS2349
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();