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

Chore: remove unused method from FileFinder (fixes #6344) #6345

Merged
merged 1 commit into from Jun 9, 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
58 changes: 0 additions & 58 deletions lib/file-finder.js
Expand Up @@ -69,64 +69,6 @@ function normalizeDirectoryEntries(entries, directory, supportedConfigs) {
return fileHash;
}

/**
* Find one instance of a specified file name in directory or in a parent directory.
* Cache the results.
* Does not check if a matching directory entry is a file, and intentionally
* only searches for the first file name in this.fileNames.
* Is currently used by lib/ignored_paths.js to find an .eslintignore file.
* @param {string} directory The directory to start the search from.
* @returns {string} Path of the file found, or an empty string if not found.
*/
FileFinder.prototype.findInDirectoryOrParents = function(directory) {
var cache = this.cache,
child,
dirs,
filePath,
i,
names,
searched;

if (!directory) {
directory = this.cwd;
}

if (cache.hasOwnProperty(directory)) {
return cache[directory];
}

dirs = [];
searched = 0;
names = this.fileNames;

(function() {
while (directory !== child) {
dirs[searched++] = directory;
var filesMap = normalizeDirectoryEntries(getDirectoryEntries(directory), directory, names);

if (Object.keys(filesMap).length) {
for (var k = 0; k < names.length; k++) {
if (filesMap[names[k]]) {
filePath = filesMap[names[k]];
return;
}
}
}

child = directory;

// Assign parent directory to directory.
directory = path.dirname(directory);
}
}());

for (i = 0; i < searched; i++) {
cache[dirs[i]] = filePath;
}

return filePath || String();
};

/**
* Find all instances of files with the specified file names, in directory and
* parent directories. Cache the results.
Expand Down
100 changes: 0 additions & 100 deletions tests/lib/file-finder.js
Expand Up @@ -26,106 +26,6 @@ describe("FileFinder", function() {
absentFileName = "4ktrgrtUTYjkopoohFe54676hnjyumlimn6r787",
uniqueFileName = "xvgRHtyH56756764535jkJ6jthty65tyhteHTEY";

describe("findInDirectoryOrParents()", function() {

describe("a searched for file that is present", function() {
var actual,
finder,
cwd = process.cwd(),
expected = path.join(fileFinderDir, ".eslintignore");

it("should be found when in the cwd", function() {
process.chdir(fileFinderDir);
finder = new FileFinder(".eslintignore", process.cwd());
actual = finder.findInDirectoryOrParents();

try {
assert.equal(actual, expected);
} finally {
process.chdir(cwd);
}
});

it("should be found when in the cwd and passed an array", function() {
process.chdir(fileFinderDir);
finder = new FileFinder([".eslintignore"], process.cwd());
actual = finder.findInDirectoryOrParents();

try {
assert.equal(actual, expected);
} finally {
process.chdir(cwd);
}
});

it("should be found when in the cwd and passed an array with a missing file", function() {
process.chdir(fileFinderDir);
finder = new FileFinder(["missing", ".eslintignore"], process.cwd());
actual = finder.findInDirectoryOrParents();

try {
assert.equal(actual, expected);
} finally {
process.chdir(cwd);
}
});

it("should be found when in a parent directory of the cwd", function() {
process.chdir(subsubsubdir);
finder = new FileFinder(".eslintignore", process.cwd());
actual = finder.findInDirectoryOrParents();

try {
assert.equal(actual, expected);
} finally {
process.chdir(cwd);
}
});

it("should be found when in a specified directory", function() {
finder = new FileFinder(".eslintignore", process.cwd());
actual = finder.findInDirectoryOrParents(fileFinderDir);

assert.equal(actual, expected);
});

it("should be found when in a parent directory of a specified directory", function() {
finder = new FileFinder(".eslintignore", process.cwd());
actual = finder.findInDirectoryOrParents(subsubsubdir);

assert.equal(actual, expected);
});

it("should be in the cache after it has been found", function() {
assert.equal(finder.cache[subsubsubdir], expected);
assert.equal(finder.cache[path.join(fileFinderDir, "subdir", "subsubdir")], expected);
assert.equal(finder.cache[path.join(fileFinderDir, "subdir")], expected);
assert.equal(finder.cache[fileFinderDir], expected);
});
});

describe("a file not present", function() {

it("should not be found, and an empty string returned", function() {
var expected = String(),
finder = new FileFinder(absentFileName, process.cwd()),
actual = finder.findInDirectoryOrParents();

assert.equal(actual, expected);
});
});

describe("Not consider directory with expected file names", function() {
it("should only find one package.json from the root", function() {
var expected = path.join(process.cwd(), "package.json");
var finder = new FileFinder("package.json", process.cwd());
var actual = finder.findInDirectoryOrParents(fileFinderDir);

assert.equal(actual, expected);
});
});
});

describe("findAllInDirectoryAndParents()", function() {
var actual,
expected,
Expand Down