Skip to content

Commit

Permalink
Don't call getPreEmitDiagnostics in tests (palantir#2769)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff authored and adidahiya committed May 15, 2017
1 parent 482fe76 commit 3a39c69
Show file tree
Hide file tree
Showing 72 changed files with 136 additions and 133 deletions.
2 changes: 2 additions & 0 deletions docs/develop/testing-rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ The following part can be any [version range](https://github.com/npm/node-semver
* You can use this system to test rules outside of the TSLint build! Use the `tslint --test path/to/dir` command to test your own custom rules.
The directory you pass should contain a `tslint.json` file and `.ts.lint` files. You can try this out on the TSLint rule test cases, for example, `tslint --test path/to/tslint-code/test/rules/quotemark/single`.

* To test rules that need type information, you can simply add a `tsconfig.json` with the desired configuration next to `tslint.json`.

* Lint failures sometimes span over multiple lines. To handle this case, don't specify a message until the end of the error. For example:

```
Expand Down
7 changes: 3 additions & 4 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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)) {
const 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 Down Expand Up @@ -111,7 +112,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 All @@ -138,8 +139,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 = {
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/defaults/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/locations/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/privacies-private/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/privacies-protected/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/privacies-public/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/privacies/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/completed-docs/visibilities/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/deprecation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/match-default-export-name/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-floating-promises/jquerypromise/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-floating-promises/promises/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-for-in-array/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
}
}
5 changes: 5 additions & 0 deletions test/rules/no-inferred-empty-object-type/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-unbound-method/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-unsafe-any/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-unused-variable/check-parameters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-unused-variable/default/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-unused-variable/ignore-pattern/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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
5 changes: 5 additions & 0 deletions test/rules/no-use-before-declare/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
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,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
Loading

0 comments on commit 3a39c69

Please sign in to comment.