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

Commit

Permalink
Fix file matching with relative tsconfig.json path (#2688)
Browse files Browse the repository at this point in the history
* Add test for tsconfig extends

* Fix problem with relative paths
  • Loading branch information
ajafff authored and nchen63 committed May 5, 2017
1 parent f86181f commit 5e76c58
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/linter.ts
Expand Up @@ -56,19 +56,15 @@ class Linter {
/**
* Creates a TypeScript program object from a tsconfig.json file path and optional project directory.
*/
public static createProgram(configFile: string, projectDirectory?: string): ts.Program {
if (projectDirectory === undefined) {
projectDirectory = path.dirname(configFile);
}

public static createProgram(configFile: string, projectDirectory: string = path.dirname(configFile)): ts.Program {
const { config } = ts.readConfigFile(configFile, ts.sys.readFile);
const parseConfigHost: ts.ParseConfigHost = {
fileExists: fs.existsSync,
readDirectory: ts.sys.readDirectory,
readFile: (file) => fs.readFileSync(file, "utf8"),
useCaseSensitiveFileNames: true,
};
const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, projectDirectory);
const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, path.resolve(projectDirectory));
const host = ts.createCompilerHost(parsed.options, true);
const program = ts.createProgram(parsed.fileNames, parsed.options, host);

Expand Down
21 changes: 21 additions & 0 deletions test/executable/executableTests.ts
Expand Up @@ -267,6 +267,27 @@ describe("Executable", function(this: Mocha.ISuiteCallbackContext) {
done();
});
});

it("can extend `tsconfig.json` with relative path", (done) => {
execCli(
["-c", "test/files/tsconfig-extends-relative/tslint-ok.json", "-p",
"test/files/tsconfig-extends-relative/test/tsconfig.json"],
(err) => {
assert.isNull(err, "process should exit without an error");
done();
});
});

it("can extend `tsconfig.json` with relative path II", (done) => {
execCli(
["-c", "test/files/tsconfig-extends-relative/tslint-fail.json", "-p",
"test/files/tsconfig-extends-relative/test/tsconfig.json"],
(err) => {
assert.isNotNull(err, "process should exit with error");
assert.strictEqual(err.code, 2, "error code should be 2");
done();
});
});
});

describe("--type-check", () => {
Expand Down
1 change: 1 addition & 0 deletions test/files/tsconfig-extends-relative/src/src.test.ts
@@ -0,0 +1 @@
export interface Test {}
1 change: 1 addition & 0 deletions test/files/tsconfig-extends-relative/test/test.test.ts
@@ -0,0 +1 @@
export interface IFoo {}
6 changes: 6 additions & 0 deletions test/files/tsconfig-extends-relative/test/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"exclude": [
"../src"
]
}
7 changes: 7 additions & 0 deletions test/files/tsconfig-extends-relative/tsconfig.json
@@ -0,0 +1,7 @@
{
"compilerOptions": {},
"include": [
"src/**/*.ts",
"test/**/*.ts"
]
}
8 changes: 8 additions & 0 deletions test/files/tsconfig-extends-relative/tslint-fail.json
@@ -0,0 +1,8 @@
{
"rules":{
"interface-name": [
true,
"never-prefix"
]
}
}
8 changes: 8 additions & 0 deletions test/files/tsconfig-extends-relative/tslint-ok.json
@@ -0,0 +1,8 @@
{
"rules":{
"interface-name": [
true,
"always-prefix"
]
}
}

0 comments on commit 5e76c58

Please sign in to comment.