diff --git a/src/configuration.ts b/src/configuration.ts index 3632b5b803d..6d66d4602b8 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -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); diff --git a/test/configurationTests.ts b/test/configurationTests.ts index 369a8f2d86e..185e05019de 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -21,6 +21,7 @@ import * as path from "path"; import { convertRuleOptions, extendConfigurationFile, + findConfigurationPath, IConfigurationFile, loadConfigurationFromPath, parseConfigFile, @@ -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"); diff --git a/test/files/config-findup/contains-config/tslint.json b/test/files/config-findup/contains-config/tslint.json new file mode 100644 index 00000000000..9e26dfeeb6e --- /dev/null +++ b/test/files/config-findup/contains-config/tslint.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/files/config-findup/no-config/index.test.ts b/test/files/config-findup/no-config/index.test.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/files/config-findup/tslint.json b/test/files/config-findup/tslint.json new file mode 100644 index 00000000000..9e26dfeeb6e --- /dev/null +++ b/test/files/config-findup/tslint.json @@ -0,0 +1 @@ +{} \ No newline at end of file