Skip to content

Commit

Permalink
Merge pull request #5528 from dchowitz/issue5496
Browse files Browse the repository at this point in the history
Fix: handle personal package.json without config (fixes #5496)
  • Loading branch information
nzakas committed Mar 17, 2016
2 parents ce88bc2 + 9289ef8 commit 3e3b17b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/config.js
Expand Up @@ -78,7 +78,7 @@ function loadConfig(configToLoad) {
* @private
*/
function getPersonalConfig() {
var config = {},
var config,
filename;

if (PERSONAL_CONFIG_DIR) {
Expand All @@ -90,7 +90,7 @@ function getPersonalConfig() {
}
}

return config;
return config || {};
}

/**
Expand Down
@@ -0,0 +1,4 @@
{
"name": "foo",
"version": "1.0.0"
}
22 changes: 22 additions & 0 deletions tests/lib/config.js
Expand Up @@ -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");
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/file-finder.js
Expand Up @@ -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);
});
});
Expand Down

0 comments on commit 3e3b17b

Please sign in to comment.