Skip to content

Commit d474443

Browse files
fix: avoid call stack overflow while processing globs (#19035)
* fix: avoid call stack overflow by processing file paths in chunks * use `flatMap()` * add comments
1 parent 7259627 commit d474443

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/eslint/eslint-helpers.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,19 @@ async function globMultiSearch({ searches, configLoader, errorOnUnmatchedPattern
421421
)
422422
);
423423

424-
const filePaths = [];
425-
424+
/*
425+
* The first loop handles errors from the glob searches. Since we can't
426+
* use `await` inside `flatMap`, we process errors separately in this loop.
427+
* This results in two iterations over `results`, but since the length is
428+
* less than or equal to the number of globs and directories passed on the
429+
* command line, the performance impact should be minimal.
430+
*/
426431
for (let i = 0; i < results.length; i++) {
427432

428433
const result = results[i];
429434
const currentSearch = normalizedSearches[i];
430435

431436
if (result.status === "fulfilled") {
432-
433-
// if the search was successful just add the results
434-
if (result.value.length > 0) {
435-
filePaths.push(...result.value);
436-
}
437-
438437
continue;
439438
}
440439

@@ -457,7 +456,8 @@ async function globMultiSearch({ searches, configLoader, errorOnUnmatchedPattern
457456

458457
}
459458

460-
return filePaths;
459+
// second loop for `fulfulled` results
460+
return results.flatMap(result => result.value);
461461

462462
}
463463

0 commit comments

Comments
 (0)