Skip to content

Commit

Permalink
Chore: remove unused method from FileFinder (fixes #6344) (#6345)
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto authored and nzakas committed Jun 9, 2016
1 parent 477fbc1 commit 977cdd5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 158 deletions.
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

0 comments on commit 977cdd5

Please sign in to comment.