diff --git a/lib/file-finder.js b/lib/file-finder.js index d78126c8366..45594057000 100644 --- a/lib/file-finder.js +++ b/lib/file-finder.js @@ -88,7 +88,9 @@ FileFinder.prototype.findAllInDirectoryAndParents = function(directory) { j, searched; - if (!directory) { + if (directory) { + directory = path.resolve(this.cwd, directory); + } else { directory = this.cwd; } diff --git a/tests/fixtures/config-hierarchy/root-true/parent/root/subdir/.eslintrc b/tests/fixtures/config-hierarchy/root-true/parent/root/subdir/.eslintrc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index 99178fdd0f0..c1571dd1f84 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -1995,6 +1995,25 @@ describe("CLIEngine", function() { }); + + it("should return the config when run from within a subdir", function() { + + var engine = new CLIEngine({ + cwd: getFixturePath("config-hierarchy", "root-true", "parent", "root", "subdir") + }); + + var configHelper = new Config(engine.options); + + var filePath = getFixturePath("config-hierarchy", "root-true", "parent", "root", ".eslintrc"); + var config = engine.getConfigForFile("./.eslintrc"); + + assert.deepEqual( + config, + configHelper.getConfig(filePath) + ); + + }); + }); describe("isPathIgnored", function() { diff --git a/tests/lib/config.js b/tests/lib/config.js index 51a71ada8ab..a1053c07c08 100644 --- a/tests/lib/config.js +++ b/tests/lib/config.js @@ -480,6 +480,20 @@ describe("Config", function() { assertConfigsEqual(actual, expected); }); + // Project configuration - root set in second level .eslintrc + it("should return project config when called with a relative path from a subdir", function() { + var configHelper = new Config({cwd: getFixturePath("root-true", "parent", "root", "subdir")}), + dir = ".", + expected = { + rules: { + semi: [2, "never"] + } + }, + actual = configHelper.getConfig(dir); + + assertConfigsEqual(actual, expected); + }); + // Command line configuration - --config with first level .eslintrc it("should merge command line config when config file adds to local .eslintrc", function() { diff --git a/tests/lib/file-finder.js b/tests/lib/file-finder.js index a838cf00af1..319854b7acc 100644 --- a/tests/lib/file-finder.js +++ b/tests/lib/file-finder.js @@ -55,6 +55,18 @@ describe("FileFinder", function() { }); }); + describe("a relative file present in a parent directory", function() { + + it("should be found, and returned as the first element of an array", function() { + finder = new FileFinder(uniqueFileName, subsubdir); + actual = finder.findAllInDirectoryAndParents("./subsubsubdir"); + expected = path.join(fileFinderDir, "subdir", uniqueFileName); + + assert.isArray(actual); + assert.equal(actual[0], expected); + }); + }); + describe("searching for multiple files", function() { it("should return only the first specified file", function() {