From 4c80417ac2975afa521379e4d8c2496da7e98a1e Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sat, 18 Jun 2016 07:27:46 +0900 Subject: [PATCH] Fix: wrong baseDir (fixes #6450) --- lib/config/config-file.js | 4 ++++ .../extends-chain-2/relative.eslintrc.json | 3 +++ tests/lib/config/config-file.js | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/fixtures/config-file/extends-chain-2/relative.eslintrc.json diff --git a/lib/config/config-file.js b/lib/config/config-file.js index e68591874c0..019fa563b02 100644 --- a/lib/config/config-file.js +++ b/lib/config/config-file.js @@ -315,6 +315,10 @@ function getBaseDir(configFilePath) { // calculates the path of the project including ESLint as dependency var projectPath = path.resolve(__dirname, "../../../"); + if (path.basename(projectPath) === "node_modules") { + projectPath = path.dirname(projectPath); + } + if (configFilePath && pathIsInside(configFilePath, projectPath)) { // be careful of https://github.com/substack/node-resolve/issues/78 diff --git a/tests/fixtures/config-file/extends-chain-2/relative.eslintrc.json b/tests/fixtures/config-file/extends-chain-2/relative.eslintrc.json new file mode 100644 index 00000000000..ad711c30b2c --- /dev/null +++ b/tests/fixtures/config-file/extends-chain-2/relative.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/eslint-config-a/index.js" +} diff --git a/tests/lib/config/config-file.js b/tests/lib/config/config-file.js index bfb80f562c8..2cb050b6876 100644 --- a/tests/lib/config/config-file.js +++ b/tests/lib/config/config-file.js @@ -657,6 +657,21 @@ describe("ConfigFile", function() { }); }); + it("should load information from `extends` chain 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 + } + }); + }); + describe("Plugins", function() { it("should load information from a YML file and load plugins", function() {