Skip to content

Commit

Permalink
Fix findup when file found in subdirectory (palantir#2765)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff authored and nchen63 committed May 19, 2017
1 parent f0e6d31 commit 5ebd054
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function findup(filename: string, directory: string): string | undefined {
while (true) { // tslint:disable-line strict-boolean-expressions
const res = findFile(directory);
if (res !== undefined) {
return res;
return path.join(directory, res);
}

const parent = path.dirname(directory);
Expand Down
18 changes: 18 additions & 0 deletions test/configurationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as path from "path";
import {
convertRuleOptions,
extendConfigurationFile,
findConfigurationPath,
IConfigurationFile,
loadConfigurationFromPath,
parseConfigFile,
Expand Down Expand Up @@ -194,6 +195,23 @@ describe("Configuration", () => {
});
});

describe("findConfigurationPath", () => {
it("finds the closest tslint.json", () => {
assert.strictEqual(
findConfigurationPath(null, "./test/files/config-findup/contains-config"),
path.resolve("test/files/config-findup/contains-config/tslint.json"),
);
assert.strictEqual(
findConfigurationPath(null, "./test/files/config-findup/no-config"),
path.resolve("./test/files/config-findup/tslint.json"),
);
assert.strictEqual(
findConfigurationPath(null, "./test/files/config-findup"),
path.resolve("./test/files/config-findup/tslint.json"),
);
});
});

describe("loadConfigurationFromPath", () => {
it("extends with relative path", () => {
const config = loadConfigurationFromPath("./test/config/tslint-extends-relative.json");
Expand Down
1 change: 1 addition & 0 deletions test/files/config-findup/contains-config/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file.
1 change: 1 addition & 0 deletions test/files/config-findup/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 5ebd054

Please sign in to comment.