Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Don't call getPreEmitDiagnostics in tests #2769

Merged
merged 7 commits into from
May 15, 2017
Merged
Changes from 3 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
13 changes: 9 additions & 4 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import * as path from "path";
import * as semver from "semver";
import * as ts from "typescript";

import { showWarningOnce } from "./error";
import {Replacement} from "./language/rule/rule";
import * as Linter from "./linter";
import {LintError} from "./test/lintError";
@@ -70,7 +71,8 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[
const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), "").results;
const tsConfig = path.join(testDirectory, "tsconfig.json");
let compilerOptions: ts.CompilerOptions = { allowJs: true };
if (fs.existsSync(tsConfig)) {
let hasConfig = fs.existsSync(tsConfig);
if (hasConfig) {
const {config, error} = ts.readConfigFile(tsConfig, ts.sys.readFile);
if (error !== undefined) {
throw new Error(JSON.stringify(error));
@@ -84,6 +86,11 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[
};
compilerOptions = ts.parseJsonConfigFileContent(config, parseConfigHost, testDirectory).options;
}
// TODO remove in v6.0.0
if (tslintConfig !== undefined && tslintConfig.linterOptions !== undefined && tslintConfig.linterOptions.typeCheck === true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linterOptions.typecheck was never public; we can remove it immediately. #1445 (comment)

hasConfig = true;
showWarningOnce("Using linterOptions.typeCheck in tests is deprecated. Place a tsconfig.json next to tslint.json instead.");
}
const results: TestResult = { directory: testDirectory, results: {} };

for (const fileToLint of filesToLint) {
@@ -115,7 +122,7 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[
const errorsFromMarkup = parse.parseErrorsFromMarkup(fileText);

let program: ts.Program | undefined;
if (tslintConfig !== undefined && tslintConfig.linterOptions !== undefined && tslintConfig.linterOptions.typeCheck === true) {
if (hasConfig) {
const compilerHost: ts.CompilerHost = {
fileExists: () => true,
getCanonicalFileName: (filename: string) => filename,
@@ -142,8 +149,6 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[
};

program = ts.createProgram([fileCompileName], compilerOptions, compilerHost);
// perform type checking on the program, updating nodes with symbol table references
ts.getPreEmitDiagnostics(program);
}

const lintOptions = {
3 changes: 0 additions & 3 deletions test/rules/await-promise/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"await-promise": true
}
1 change: 1 addition & 0 deletions test/rules/completed-docs/defaults/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an empty file looks pretty weird; can we at least make it extend some common tsconfig file? perhaps located at test/rules/test-tsconfig.json?

Copy link
Contributor Author

@ajafff ajafff May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to extend because that adds unnecessary overhead. I just added compilerOptions.module to have some config in the file.
Edit: target caused some problems, that's why I used module

3 changes: 0 additions & 3 deletions test/rules/completed-docs/defaults/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": true
}
1 change: 1 addition & 0 deletions test/rules/completed-docs/locations/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/locations/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [true, {
"methods": {
1 change: 1 addition & 0 deletions test/rules/completed-docs/privacies-private/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/privacies-private/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [true, {
"methods": {
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/privacies-protected/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [true, {
"methods": {
1 change: 1 addition & 0 deletions test/rules/completed-docs/privacies-public/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/privacies-public/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [true, {
"methods": {
1 change: 1 addition & 0 deletions test/rules/completed-docs/privacies/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/privacies/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [true, {
"methods": {
1 change: 1 addition & 0 deletions test/rules/completed-docs/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/types/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [
true,
1 change: 1 addition & 0 deletions test/rules/completed-docs/visibilities/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/completed-docs/visibilities/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"completed-docs": [true, {
"enums": {
1 change: 1 addition & 0 deletions test/rules/deprecation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/deprecation/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"deprecation": true
}
1 change: 1 addition & 0 deletions test/rules/match-default-export-name/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/match-default-export-name/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"match-default-export-name": true
}
3 changes: 0 additions & 3 deletions test/rules/no-boolean-literal-compare/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-boolean-literal-compare": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-floating-promises/jquerypromise/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-floating-promises": [true, "JQueryPromise"]
}
1 change: 1 addition & 0 deletions test/rules/no-floating-promises/promises/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-floating-promises/promises/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-floating-promises": true
}
1 change: 1 addition & 0 deletions test/rules/no-for-in-array/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-for-in-array/tslint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"rules": {
"no-for-in-array": true
},
"linterOptions": {
"typeCheck": true
}
}
1 change: 1 addition & 0 deletions test/rules/no-import-side-effect/default/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// valid cases
import {Injectable, Component, Directive} from '@angular/core';
import {Inject} from '@angular/core';
3 changes: 0 additions & 3 deletions test/rules/no-import-side-effect/default/tslint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"rules": {
"no-import-side-effect": [true]
},
"linterOptions": {
"typeCheck": false
}
}
3 changes: 0 additions & 3 deletions test/rules/no-import-side-effect/ignore-module/tslint.json
Original file line number Diff line number Diff line change
@@ -6,8 +6,5 @@
"ignore-module": "(allow-side-effect|\\.css)$"
}
]
},
"linterOptions": {
"typeCheck": false
}
}
1 change: 1 addition & 0 deletions test/rules/no-inferred-empty-object-type/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-inferred-empty-object-type/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-inferred-empty-object-type": true
}
1 change: 1 addition & 0 deletions test/rules/no-unbound-method/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-unbound-method/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unbound-method": true
}
3 changes: 0 additions & 3 deletions test/rules/no-unnecessary-qualifier/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unnecessary-qualifier": true
}
3 changes: 0 additions & 3 deletions test/rules/no-unnecessary-type-assertion/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unnecessary-type-assertion": true
}
1 change: 1 addition & 0 deletions test/rules/no-unsafe-any/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-unsafe-any/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unsafe-any": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-unused-variable/check-parameters/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unused-variable": [true, "check-parameters"]
}
1 change: 1 addition & 0 deletions test/rules/no-unused-variable/default/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-unused-variable/default/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unused-variable": true
}
1 change: 1 addition & 0 deletions test/rules/no-unused-variable/ignore-pattern/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-unused-variable/ignore-pattern/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unused-variable": [true, {"ignore-pattern": "^[_R]"}]
}
3 changes: 0 additions & 3 deletions test/rules/no-unused-variable/type-checked/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-unused-variable": true
}
1 change: 1 addition & 0 deletions test/rules/no-use-before-declare/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/no-use-before-declare/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-use-before-declare": true
}
3 changes: 0 additions & 3 deletions test/rules/no-void-expression/default/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-void-expression": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
}
1 change: 1 addition & 0 deletions test/rules/promise-function-async/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/promise-function-async/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"promise-function-async": true
}
1 change: 1 addition & 0 deletions test/rules/restrict-plus-operands/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 0 additions & 3 deletions test/rules/restrict-plus-operands/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"restrict-plus-operands": true
}
3 changes: 0 additions & 3 deletions test/rules/return-undefined/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"return-undefined": true
}
3 changes: 0 additions & 3 deletions test/rules/strict-boolean-expressions/allow-mix/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-string", "allow-undefined-union", "allow-mix"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-null-union"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-number"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-string"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-undefined-union"]
}
Loading