Skip to content

Commit

Permalink
Add linterOptions to tslint.json (palantir#1403)
Browse files Browse the repository at this point in the history
* Add linterOptions to tslint.json

- only enable type checking during tests when typeCheck: true is configured
- fixes palantir#1402

* Code style
  • Loading branch information
adidahiya authored and Nina Hartmann committed Aug 31, 2016
1 parent 9cfc5b7 commit 6b056cc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import {arrayify, objectify, stripComments} from "./utils";

export interface IConfigurationFile {
extends?: string | string[];
linterOptions?: {
typeCheck?: boolean,
};
rulesDirectory?: string | string[];
rules?: any;
}
Expand Down
47 changes: 25 additions & 22 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions test/rules/restrict-plus-operands/tslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"linterOptions": {
"typeCheck": true
},
"rules": {
"restrict-plus-operands": true
}
Expand Down

0 comments on commit 6b056cc

Please sign in to comment.