Skip to content

Commit

Permalink
Fix: wrong baseDir (fixes #6450) (#6457)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and nzakas committed Jun 20, 2016
1 parent 3c9ce09 commit 434de7f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
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

0 comments on commit 434de7f

Please sign in to comment.