summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/file-finder.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/file-finder.js')
-rw-r--r--tools/eslint/lib/file-finder.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/tools/eslint/lib/file-finder.js b/tools/eslint/lib/file-finder.js
index acb886c9d1..3458bbf52a 100644
--- a/tools/eslint/lib/file-finder.js
+++ b/tools/eslint/lib/file-finder.js
@@ -25,6 +25,7 @@ const fs = require("fs"),
*/
function getDirectoryEntries(directory) {
try {
+
return fs.readdirSync(directory);
} catch (ex) {
return [];
@@ -79,9 +80,9 @@ class FileFinder {
* Searches for all the file names in this.fileNames.
* Is currently used by lib/config.js to find .eslintrc and package.json files.
* @param {string} directory The directory to start the search from.
- * @returns {string[]} The file paths found.
+ * @returns {GeneratorFunction} to iterate the file paths found
*/
- findAllInDirectoryAndParents(directory) {
+ *findAllInDirectoryAndParents(directory) {
const cache = this.cache;
if (directory) {
@@ -91,7 +92,8 @@ class FileFinder {
}
if (cache.hasOwnProperty(directory)) {
- return cache[directory];
+ yield* cache[directory];
+ return; // to avoid doing the normal loop afterwards
}
const dirs = [];
@@ -114,19 +116,21 @@ class FileFinder {
for (let j = 0; j < searched; j++) {
cache[dirs[j]].push(filePath);
}
-
+ yield filePath;
break;
}
}
}
+
const child = directory;
// Assign parent directory to directory.
directory = path.dirname(directory);
if (directory === child) {
- return cache[dirs[0]];
+ return;
}
+
} while (!cache.hasOwnProperty(directory));
// Add what has been cached previously to the cache of each directory searched.
@@ -134,7 +138,7 @@ class FileFinder {
dirs.push.apply(cache[dirs[i]], cache[directory]);
}
- return cache[dirs[0]];
+ yield* cache[dirs[0]];
}
}