From f4ae526529b50396c27b054d99c21db7e998891b Mon Sep 17 00:00:00 2001 From: alberto Date: Wed, 8 Jun 2016 23:45:16 +0200 Subject: [PATCH] Chore: remove unused method from FileFinder (fixes #6344) --- lib/file-finder.js | 58 ----------------------- tests/lib/file-finder.js | 100 --------------------------------------- 2 files changed, 158 deletions(-) diff --git a/lib/file-finder.js b/lib/file-finder.js index 4dbb7544a37..d78126c8366 100644 --- a/lib/file-finder.js +++ b/lib/file-finder.js @@ -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. diff --git a/tests/lib/file-finder.js b/tests/lib/file-finder.js index 0b05324fba6..a838cf00af1 100644 --- a/tests/lib/file-finder.js +++ b/tests/lib/file-finder.js @@ -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,