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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
create a program when tsconfig.json is found
  • Loading branch information
ajafff committed May 15, 2017
commit 96d7782b94d8a1fb74bc833e5207d7fa18bda0d1
10 changes: 8 additions & 2 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand All @@ -84,6 +86,10 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[
};
compilerOptions = ts.parseJsonConfigFileContent(config, parseConfigHost, testDirectory).options;
}
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 in the directory instead");
}
const results: TestResult = { directory: testDirectory, results: {} };

for (const fileToLint of filesToLint) {
Expand Down Expand Up @@ -115,7 +121,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,
Expand Down
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
}
Expand Down
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
}
Expand Down
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": {
Expand Down
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": {
Expand Down
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": {
Expand Down
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": {
Expand Down
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": {
Expand Down
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,
Expand Down
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": {
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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"]
}
Expand Down
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
}
Expand Down
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';
Expand Down
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
Expand Up @@ -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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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"]
}
Expand Down
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
}
Expand Down
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]"}]
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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"]
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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
}
Expand Down
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"]
}
Expand Down
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"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-number"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": [true, "allow-string"]
}
Expand Down
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"]
}
Expand Down
3 changes: 0 additions & 3 deletions test/rules/strict-boolean-expressions/default/tslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"strict-boolean-expressions": true
}
Expand Down
Loading