mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
don't emit "unused @ts-expect-error" in unchecked js files (#40046)
* don't emit unused ts-expect-error in unchecked js files * simplify code
This commit is contained in:
@@ -1747,13 +1747,13 @@ namespace ts {
|
||||
const bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
|
||||
const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
|
||||
|
||||
return getMergedBindAndCheckDiagnostics(sourceFile, bindDiagnostics, checkDiagnostics, isCheckJs ? sourceFile.jsDocDiagnostics : undefined);
|
||||
return getMergedBindAndCheckDiagnostics(sourceFile, includeBindAndCheckDiagnostics, bindDiagnostics, checkDiagnostics, isCheckJs ? sourceFile.jsDocDiagnostics : undefined);
|
||||
});
|
||||
}
|
||||
|
||||
function getMergedBindAndCheckDiagnostics(sourceFile: SourceFile, ...allDiagnostics: (readonly Diagnostic[] | undefined)[]) {
|
||||
function getMergedBindAndCheckDiagnostics(sourceFile: SourceFile, includeBindAndCheckDiagnostics: boolean, ...allDiagnostics: (readonly Diagnostic[] | undefined)[]) {
|
||||
const flatDiagnostics = flatten(allDiagnostics);
|
||||
if (!sourceFile.commentDirectives?.length) {
|
||||
if (!includeBindAndCheckDiagnostics || !sourceFile.commentDirectives?.length) {
|
||||
return flatDiagnostics;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/conformance/directives/a.js(3,1): error TS2578: Unused '@ts-expect-error' directive.
|
||||
|
||||
|
||||
==== tests/cases/conformance/directives/a.js (1 errors) ====
|
||||
// there should be a "Unused @ts-expect-error" error since js files are being checked
|
||||
|
||||
// @ts-expect-error
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2578: Unused '@ts-expect-error' directive.
|
||||
const a = 1;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/conformance/directives/a.js ===
|
||||
// there should be a "Unused @ts-expect-error" error since js files are being checked
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
>a : Symbol(a, Decl(a.js, 3, 5))
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/directives/a.js ===
|
||||
// there should be a "Unused @ts-expect-error" error since js files are being checked
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
=== tests/cases/conformance/directives/a.js ===
|
||||
// there should not be a "Unused @ts-expect-error" error since js files are not being checked
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
>a : Symbol(a, Decl(a.js, 3, 5))
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/directives/a.js ===
|
||||
// there should not be a "Unused @ts-expect-error" error since js files are not being checked
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [ts-expect-error-nocheck.ts]
|
||||
// @ts-nocheck
|
||||
|
||||
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
|
||||
|
||||
//// [ts-expect-error-nocheck.js]
|
||||
// @ts-nocheck
|
||||
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
|
||||
// @ts-expect-error
|
||||
var a = 1;
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/conformance/directives/ts-expect-error-nocheck.ts ===
|
||||
// @ts-nocheck
|
||||
|
||||
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
>a : Symbol(a, Decl(ts-expect-error-nocheck.ts, 5, 5))
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/conformance/directives/ts-expect-error-nocheck.ts ===
|
||||
// @ts-nocheck
|
||||
|
||||
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @fileName: a.js
|
||||
|
||||
// there should be a "Unused @ts-expect-error" error since js files are being checked
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
@@ -0,0 +1,10 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: false
|
||||
// @noEmit: true
|
||||
|
||||
// @fileName: a.js
|
||||
|
||||
// there should not be a "Unused @ts-expect-error" error since js files are not being checked
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
@@ -0,0 +1,6 @@
|
||||
// @ts-nocheck
|
||||
|
||||
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
|
||||
|
||||
// @ts-expect-error
|
||||
const a = 1;
|
||||
Reference in New Issue
Block a user