Skip to content

Commit

Permalink
Fix: --print-config return config inside subdir (fixes #6329)
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto committed Jun 11, 2016
1 parent 6b08cfc commit 4ef5d6a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/file-finder.js
Expand Up @@ -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;
}

Expand Down
Empty file.
19 changes: 19 additions & 0 deletions tests/lib/cli-engine.js
Expand Up @@ -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() {
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/config.js
Expand Up @@ -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() {

Expand Down
12 changes: 12 additions & 0 deletions tests/lib/file-finder.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 4ef5d6a

Please sign in to comment.