Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: --print-config return config inside subdir (fixes #6329) #6385

Merged
merged 1 commit into from Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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