From 6b056cc0225fe9f2bac579d6b4960b54bf6497c3 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 18 Jul 2016 22:45:22 -0400 Subject: [PATCH] Add linterOptions to tslint.json (#1403) * Add linterOptions to tslint.json - only enable type checking during tests when typeCheck: true is configured - fixes #1402 * Code style --- src/configuration.ts | 3 ++ src/test.ts | 47 ++++++++++--------- test/rules/restrict-plus-operands/tslint.json | 3 ++ 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index ee1e98d0eff..a7efe05e985 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -24,6 +24,9 @@ import {arrayify, objectify, stripComments} from "./utils"; export interface IConfigurationFile { extends?: string | string[]; + linterOptions?: { + typeCheck?: boolean, + }; rulesDirectory?: string | string[]; rules?: any; } diff --git a/src/test.ts b/src/test.ts index ffe669fc1b9..6888b22e9fb 100644 --- a/src/test.ts +++ b/src/test.ts @@ -53,29 +53,32 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[ const fileTextWithoutMarkup = parse.removeErrorMarkup(fileText); const errorsFromMarkup = parse.parseErrorsFromMarkup(fileText); - const compilerOptions = createCompilerOptions(); - const compilerHost: ts.CompilerHost = { - fileExists: () => true, - getCanonicalFileName: (filename: string) => filename, - getCurrentDirectory: () => "", - getDefaultLibFileName: () => ts.getDefaultLibFileName(compilerOptions), - getNewLine: () => "\n", - getSourceFile: function (filenameToGet: string) { - if (filenameToGet === this.getDefaultLibFileName()) { - const fileText = fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString(); - return ts.createSourceFile(filenameToGet, fileText, compilerOptions.target); - } else if (filenameToGet === fileCompileName) { - return ts.createSourceFile(fileBasename, fileTextWithoutMarkup, compilerOptions.target, true); - } - }, - readFile: () => null, - useCaseSensitiveFileNames: () => true, - writeFile: () => null, - }; + let program: ts.Program; + if (tslintConfig.linterOptions && tslintConfig.linterOptions.typeCheck) { + const compilerOptions = createCompilerOptions(); + const compilerHost: ts.CompilerHost = { + fileExists: () => true, + getCanonicalFileName: (filename: string) => filename, + getCurrentDirectory: () => "", + getDefaultLibFileName: () => ts.getDefaultLibFileName(compilerOptions), + getNewLine: () => "\n", + getSourceFile: function (filenameToGet: string) { + if (filenameToGet === this.getDefaultLibFileName()) { + const fileText = fs.readFileSync(ts.getDefaultLibFilePath(compilerOptions)).toString(); + return ts.createSourceFile(filenameToGet, fileText, compilerOptions.target); + } else if (filenameToGet === fileCompileName) { + return ts.createSourceFile(fileBasename, fileTextWithoutMarkup, compilerOptions.target, true); + } + }, + readFile: () => null, + useCaseSensitiveFileNames: () => true, + writeFile: () => null, + }; - const program = ts.createProgram([fileCompileName], compilerOptions, compilerHost); - // perform type checking on the program, updating nodes with symbol table references - ts.getPreEmitDiagnostics(program); + program = ts.createProgram([fileCompileName], compilerOptions, compilerHost); + // perform type checking on the program, updating nodes with symbol table references + ts.getPreEmitDiagnostics(program); + } const lintOptions = { configuration: tslintConfig, diff --git a/test/rules/restrict-plus-operands/tslint.json b/test/rules/restrict-plus-operands/tslint.json index 8389b1de47a..5337f453195 100644 --- a/test/rules/restrict-plus-operands/tslint.json +++ b/test/rules/restrict-plus-operands/tslint.json @@ -1,4 +1,7 @@ { + "linterOptions": { + "typeCheck": true + }, "rules": { "restrict-plus-operands": true }