Skip to content

Commit

Permalink
Respect //@ts-nocheck in TS files
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Sep 11, 2019
1 parent f9cc374 commit 30ed2fb
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
57 changes: 57 additions & 0 deletions tests/baselines/reference/tsNoCheckForTypescript.js
Original file line number Diff line number Diff line change
@@ -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'.
}

21 changes: 21 additions & 0 deletions tests/baselines/reference/tsNoCheckForTypescript.symbols
Original file line number Diff line number Diff line change
@@ -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))
}

22 changes: 22 additions & 0 deletions tests/baselines/reference/tsNoCheckForTypescript.types
Original file line number Diff line number Diff line change
@@ -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"
}

14 changes: 14 additions & 0 deletions tests/cases/conformance/jsdoc/tsNoCheckForTypescript.ts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion tests/cases/user/prettier/prettier
2 changes: 1 addition & 1 deletion tests/cases/user/puppeteer/puppeteer
2 changes: 1 addition & 1 deletion tests/cases/user/webpack/webpack
Submodule webpack updated 36 files
+0 −24 .eslintignore
+6 −9 .eslintrc.js
+1 −1 .gitignore
+1 −1 README.md
+14 −12 lib/CachePlugin.js
+1 −1 lib/Parser.js
+14 −49 lib/buildChunkGraph.js
+7 −13 lib/wasm/WebAssemblyGenerator.js
+3 −3 package.json
+0 −1 test/configCases/chunk-graph/issue-9634/async-b.js
+0 −1 test/configCases/chunk-graph/issue-9634/async-b2.js
+0 −13 test/configCases/chunk-graph/issue-9634/entry-a.js
+0 −11 test/configCases/chunk-graph/issue-9634/entry-b.js
+0 −1 test/configCases/chunk-graph/issue-9634/leaf.js
+0 −3 test/configCases/chunk-graph/issue-9634/module.js
+0 −1 test/configCases/chunk-graph/issue-9634/shared.js
+0 −5 test/configCases/chunk-graph/issue-9634/test.config.js
+0 −9 test/configCases/chunk-graph/issue-9634/webpack.config.js
+19 −22 test/helpers/PluginEnvironment.js
+1 −1 test/helpers/TemplatePluginEnvironment.js
+3 −3 test/helpers/applyPluginWithOptions.js
+1 −1 test/helpers/createLazyTestEnv.js
+1 −4 test/helpers/remove.js
+4 −5 test/helpers/supportDefaultAssignment.js
+2 −4 test/helpers/supportsArrowFunctionExpression.js
+2 −4 test/helpers/supportsBlockScoping.js
+1 −1 test/helpers/supportsDefaultArgs.js
+1 −1 test/helpers/supportsES6.js
+2 −2 test/helpers/supportsForOf.js
+1 −1 test/helpers/supportsIteratorDestructuring.js
+1 −1 test/helpers/supportsObjectDestructuring.js
+1 −1 test/helpers/supportsOptionalCatchBinding.js
+2 −3 test/helpers/supportsSpread.js
+1 −1 test/helpers/supportsTemplateStrings.js
+1 −1 test/helpers/supportsWebAssembly.js
+43 −40 yarn.lock

0 comments on commit 30ed2fb

Please sign in to comment.