From 3227b3359f3c9d3ab1da36e231b050584b860472 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 11 Sep 2019 15:41:00 -0700 Subject: [PATCH] Respect //@ts-nocheck in TS files --- .vscode/settings.json | 6 +- src/compiler/program.ts | 3 +- .../reference/tsNoCheckForTypescript.js | 57 +++++++++++++++++++ .../reference/tsNoCheckForTypescript.symbols | 21 +++++++ .../reference/tsNoCheckForTypescript.types | 22 +++++++ .../jsdoc/tsNoCheckForTypescript.ts | 14 +++++ .../TypeScript-Node-Starter | 2 +- .../TypeScript-React-Starter | 2 +- tests/cases/user/axios-src/axios-src | 2 +- .../user/create-react-app/create-react-app | 2 +- tests/cases/user/prettier/prettier | 2 +- tests/cases/user/puppeteer/puppeteer | 2 +- tests/cases/user/webpack/webpack | 2 +- 13 files changed, 128 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/tsNoCheckForTypescript.js create mode 100644 tests/baselines/reference/tsNoCheckForTypescript.symbols create mode 100644 tests/baselines/reference/tsNoCheckForTypescript.types create mode 100644 tests/cases/conformance/jsdoc/tsNoCheckForTypescript.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 4f481751900d2..e0e46f25783c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,9 @@ "rulePaths": ["../scripts/eslint/built/rules/"], "ext": [".ts"] }, - "eslint.workingDirectories": ["./src", "./scripts"] + "eslint.workingDirectories": [ + "./src", + "./scripts" + ], + "terminal.integrated.rendererType": "dom" } \ No newline at end of file diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 275acb64641de..6d1e0883065c4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1691,8 +1691,9 @@ namespace ts { Debug.assert(!!sourceFile.bindDiagnostics); const isCheckJs = isCheckJsEnabledForFile(sourceFile, options); + const isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false; // By default, only type-check .ts, .tsx, 'Deferred' and 'External' files (external files are added by plugins) - const includeBindAndCheckDiagnostics = sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX || + const includeBindAndCheckDiagnostics = !isTsNoCheck && sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX || sourceFile.scriptKind === ScriptKind.External || isCheckJs || sourceFile.scriptKind === ScriptKind.Deferred; const bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray; const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray; diff --git a/tests/baselines/reference/tsNoCheckForTypescript.js b/tests/baselines/reference/tsNoCheckForTypescript.js new file mode 100644 index 0000000000000..334db412ea418 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescript.js @@ -0,0 +1,57 @@ +//// [file.ts] +// @ts-nocheck + +export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment + +export interface Aleph { + q: number; +} + +export class Bet implements Aleph { + q: string = "lol" // And so will this implements error +} + + +//// [file.js] +"use strict"; +// @ts-nocheck +exports.__esModule = true; +exports.a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment +var Bet = /** @class */ (function () { + function Bet() { + this.q = "lol"; // And so will this implements error + } + return Bet; +}()); +exports.Bet = Bet; + + +//// [file.d.ts] +export declare const a: any; +export interface Aleph { + q: number; +} +export declare class Bet implements Aleph { + q: string; +} + + +//// [DtsFileErrors] + + +tests/cases/conformance/jsdoc/file.d.ts(6,5): error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/jsdoc/file.d.ts (1 errors) ==== + export declare const a: any; + export interface Aleph { + q: number; + } + export declare class Bet implements Aleph { + q: string; + ~ +!!! error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'. +!!! error TS2416: Type 'string' is not assignable to type 'number'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/tsNoCheckForTypescript.symbols b/tests/baselines/reference/tsNoCheckForTypescript.symbols new file mode 100644 index 0000000000000..ce3636a23e804 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescript.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/jsdoc/file.ts === +// @ts-nocheck + +export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment +>a : Symbol(a, Decl(file.ts, 2, 12)) + +export interface Aleph { +>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24)) + + q: number; +>q : Symbol(Aleph.q, Decl(file.ts, 4, 24)) +} + +export class Bet implements Aleph { +>Bet : Symbol(Bet, Decl(file.ts, 6, 1)) +>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24)) + + q: string = "lol" // And so will this implements error +>q : Symbol(Bet.q, Decl(file.ts, 8, 35)) +} + diff --git a/tests/baselines/reference/tsNoCheckForTypescript.types b/tests/baselines/reference/tsNoCheckForTypescript.types new file mode 100644 index 0000000000000..a87c71e1ccb27 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescript.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/jsdoc/file.ts === +// @ts-nocheck + +export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment +>a : any +>1 + {} : any +>1 : 1 +>{} : {} + +export interface Aleph { + q: number; +>q : number +} + +export class Bet implements Aleph { +>Bet : Bet + + q: string = "lol" // And so will this implements error +>q : string +>"lol" : "lol" +} + diff --git a/tests/cases/conformance/jsdoc/tsNoCheckForTypescript.ts b/tests/cases/conformance/jsdoc/tsNoCheckForTypescript.ts new file mode 100644 index 0000000000000..3c8933fc8203f --- /dev/null +++ b/tests/cases/conformance/jsdoc/tsNoCheckForTypescript.ts @@ -0,0 +1,14 @@ +// @declaration: true +// @filename: file.ts + +// @ts-nocheck + +export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment + +export interface Aleph { + q: number; +} + +export class Bet implements Aleph { + q: string = "lol" // And so will this implements error +} diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter index ca14e7ccbca8a..1bf5836cae524 160000 --- a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -1 +1 @@ -Subproject commit ca14e7ccbca8a821d3b860ebb6f3c81c68ccbd06 +Subproject commit 1bf5836cae5246b89bbf7063c3e84e110222fcdf diff --git a/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter b/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter index 19c71f2c6a2b8..bfc20b2f17c02 160000 --- a/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter +++ b/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter @@ -1 +1 @@ -Subproject commit 19c71f2c6a2b874b1b2bb28a8526b19185b8eece +Subproject commit bfc20b2f17c0206105e2cdd42cd35d79dd03a884 diff --git a/tests/cases/user/axios-src/axios-src b/tests/cases/user/axios-src/axios-src index 6a4a85c57fcab..2ee3b482456cd 160000 --- a/tests/cases/user/axios-src/axios-src +++ b/tests/cases/user/axios-src/axios-src @@ -1 +1 @@ -Subproject commit 6a4a85c57fcaba912eee61b87ba34d07323bc60c +Subproject commit 2ee3b482456cd2a09ccbd3a4b0c20f3d0c5a5644 diff --git a/tests/cases/user/create-react-app/create-react-app b/tests/cases/user/create-react-app/create-react-app index c9b95047b979b..437b83f0337a5 160000 --- a/tests/cases/user/create-react-app/create-react-app +++ b/tests/cases/user/create-react-app/create-react-app @@ -1 +1 @@ -Subproject commit c9b95047b979bebe89ee70590b2a32ab67ef68af +Subproject commit 437b83f0337a5d57ce7dd976d2c3b44cb2037e45 diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 9f5bd298db26f..2314640485001 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 9f5bd298db26f76e95ad17f8406edd7ebefacc5a +Subproject commit 23146404850011972f695fb6bc2b8113c3cffbfc diff --git a/tests/cases/user/puppeteer/puppeteer b/tests/cases/user/puppeteer/puppeteer index c2651c2b5cc88..b6b29502eb6a7 160000 --- a/tests/cases/user/puppeteer/puppeteer +++ b/tests/cases/user/puppeteer/puppeteer @@ -1 +1 @@ -Subproject commit c2651c2b5cc888ebd0ca6be87063d9f98b9eb59c +Subproject commit b6b29502eb6a75fe3869806f0e7b27195fe51b0d diff --git a/tests/cases/user/webpack/webpack b/tests/cases/user/webpack/webpack index 77cd3d0cff39d..743ae6da9a6fc 160000 --- a/tests/cases/user/webpack/webpack +++ b/tests/cases/user/webpack/webpack @@ -1 +1 @@ -Subproject commit 77cd3d0cff39def2f8bd6355dcd270dd80bc5da2 +Subproject commit 743ae6da9a6fc3b459a7ab3bb250fb07d14f9c5d