diff --git a/lib/config.js b/lib/config.js index 2d8bba9c8a9..2798eee8f51 100644 --- a/lib/config.js +++ b/lib/config.js @@ -78,7 +78,7 @@ function loadConfig(configToLoad) { * @private */ function getPersonalConfig() { - var config = {}, + var config, filename; if (PERSONAL_CONFIG_DIR) { @@ -90,7 +90,7 @@ function getPersonalConfig() { } } - return config; + return config || {}; } /** diff --git a/tests/fixtures/config-hierarchy/personal-config/home-folder-with-packagejson/package.json b/tests/fixtures/config-hierarchy/personal-config/home-folder-with-packagejson/package.json new file mode 100644 index 00000000000..b113b49c495 --- /dev/null +++ b/tests/fixtures/config-hierarchy/personal-config/home-folder-with-packagejson/package.json @@ -0,0 +1,4 @@ +{ + "name": "foo", + "version": "1.0.0" +} \ No newline at end of file diff --git a/tests/lib/config.js b/tests/lib/config.js index 05d4a032472..513b46210bb 100644 --- a/tests/lib/config.js +++ b/tests/lib/config.js @@ -828,6 +828,28 @@ describe("Config", function() { assert.deepEqual(actual, expected); }); + it("should have an empty config if no local config was found and ~/package.json contains no eslintConfig section", function() { + var projectPath = getFixturePath("personal-config", "project-without-config"), + homePath = getFixturePath("personal-config", "home-folder-with-packagejson"), + filePath = getFixturePath("personal-config", "project-without-config", "foo.js"); + + getCwd.returns(projectPath); + + var StubbedConfig = proxyquire("../../lib/config", { "user-home": homePath }); + + var config = new StubbedConfig({ cwd: process.cwd() }), + actual = config.getConfig(filePath), + expected = { + parserOptions: {}, + env: {}, + globals: {}, + parser: void 0, + rules: {} + }; + + assert.deepEqual(actual, expected); + }); + it("should still load the project config if the current working directory is the same as the home folder", function() { var projectPath = getFixturePath("personal-config", "project-with-config"), filePath = getFixturePath("personal-config", "project-with-config", "subfolder", "foo.js"); diff --git a/tests/lib/file-finder.js b/tests/lib/file-finder.js index f4cb918513d..0b05324fba6 100644 --- a/tests/lib/file-finder.js +++ b/tests/lib/file-finder.js @@ -235,11 +235,31 @@ describe("FileFinder", function() { }); }); + /** + * The intention of this test case is not clear to me. It seems + * to be a special case of "a file present in a parent directory" above. + * Apart from that: Searching for package.json up to the root + * is kind of non-deterministic for testing purposes. A unique file name + * and/or restricting the search up to the workspace root (not /) would + * be better. The original code assumed there will never be a package.json + * outside of the eslint workspace, but that cannot be guaranteed. + */ describe("Not consider directory with expected file names", function() { it("should only find one package.json from the root", function() { expected = path.join(process.cwd(), "package.json"); finder = new FileFinder("package.json", process.cwd()); actual = finder.findAllInDirectoryAndParents(fileFinderDir); + + /** + * Filter files outside of current workspace, otherwise test fails, + * if there is for example a ~/package.json file. + * In order to eliminate side effects of files located outside of + * workspace this should be done for all test cases here. + */ + actual = actual.filter(function(file) { + return (file || "").indexOf(process.cwd()) === 0; + }); + assert.equal(actual, expected); }); });