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: wrong baseDir (fixes #6450) #6457

Merged
merged 1 commit into from Jun 20, 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
5 changes: 2 additions & 3 deletions lib/config/config-file.js
Expand Up @@ -495,7 +495,6 @@ function resolve(filePath, relativeTo) {
function load(filePath, applyEnvironments, relativeTo) {
var resolvedPath = resolve(filePath, relativeTo),
dirname = path.dirname(resolvedPath.filePath),
basedir = getBaseDir(dirname),
lookupPath = getLookupPath(dirname),
config = loadConfigFile(resolvedPath);

Expand All @@ -514,7 +513,7 @@ function load(filePath, applyEnvironments, relativeTo) {
// include full path of parser if present
if (config.parser) {
if (isFilePath(config.parser)) {
config.parser = path.resolve(basedir || "", config.parser);
config.parser = path.resolve(dirname || "", config.parser);
} else {
config.parser = resolver.resolve(config.parser, lookupPath);
}
Expand All @@ -528,7 +527,7 @@ function load(filePath, applyEnvironments, relativeTo) {
* a "parent". Load the referenced file and merge the configuration recursively.
*/
if (config.extends) {
config = applyExtends(config, filePath, basedir);
config = applyExtends(config, filePath, dirname);
}

if (config.env && applyEnvironments) {
Expand Down
@@ -0,0 +1,3 @@
{
"parser": "./parser.js"
}
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/eslint-config-a/index.js"
}
73 changes: 73 additions & 0 deletions tests/lib/config/config-file.js
Expand Up @@ -17,6 +17,7 @@ var assert = require("chai").assert,
yaml = require("js-yaml"),
userHome = require("user-home"),
proxyquire = require("proxyquire"),
shell = require("shelljs"),
environments = require("../../../conf/environments"),
ConfigFile = require("../../../lib/config/config-file");

Expand Down Expand Up @@ -657,6 +658,78 @@ describe("ConfigFile", function() {
});
});

it("should load information from `extends` chain in .eslintrc with relative path.", function() {
var config = ConfigFile.load(getFixturePath("extends-chain-2/relative.eslintrc.json"));

assert.deepEqual(config, {
env: {},
extends: "./node_modules/eslint-config-a/index.js",
globals: {},
parserOptions: {},
rules: {
a: 2, // from node_modules/eslint-config-a/index.js
relative: 2 // from node_modules/eslint-config-a/relative.js
}
});
});

it("should load information from `parser` in .eslintrc with relative path.", function() {
var config = ConfigFile.load(getFixturePath("extends-chain-2/parser.eslintrc.json"));
var parserPath = getFixturePath("extends-chain-2/parser.js");

assert.deepEqual(config, {
env: {},
globals: {},
parser: parserPath,
parserOptions: {},
rules: {}
});
});

describe("even if it's in another directory,", function() {
var fixturePath = "";

before(function() {
var tempDir = temp.mkdirSync("eslint-test-chain");
var chain2 = getFixturePath("extends-chain-2");

fixturePath = path.join(tempDir, "extends-chain-2");
shell.cp("-r", chain2, fixturePath);
});

after(function() {
temp.cleanupSync();
});

it("should load information from `extends` chain in .eslintrc with relative path.", function() {
var config = ConfigFile.load(path.join(fixturePath, "relative.eslintrc.json"));

assert.deepEqual(config, {
env: {},
extends: "./node_modules/eslint-config-a/index.js",
globals: {},
parserOptions: {},
rules: {
a: 2, // from node_modules/eslint-config-a/index.js
relative: 2 // from node_modules/eslint-config-a/relative.js
}
});
});

it("should load information from `parser` in .eslintrc with relative path.", function() {
var config = ConfigFile.load(path.join(fixturePath, "parser.eslintrc.json"));
var parserPath = path.join(fixturePath, "parser.js");

assert.deepEqual(config, {
env: {},
globals: {},
parser: parserPath,
parserOptions: {},
rules: {}
});
});
});

describe("Plugins", function() {

it("should load information from a YML file and load plugins", function() {
Expand Down