Skip to content

Commit

Permalink
fix: avoid call stack overflow while processing globs (#19035)
Browse files Browse the repository at this point in the history
* fix: avoid call stack overflow by processing file paths in chunks

* use `flatMap()`

* add comments
  • Loading branch information
LiviaMedeiros authored Oct 23, 2024
1 parent 7259627 commit d474443
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/eslint/eslint-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,20 +421,19 @@ async function globMultiSearch({ searches, configLoader, errorOnUnmatchedPattern
)
);

const filePaths = [];

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

const result = results[i];
const currentSearch = normalizedSearches[i];

if (result.status === "fulfilled") {

// if the search was successful just add the results
if (result.value.length > 0) {
filePaths.push(...result.value);
}

continue;
}

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

}

return filePaths;
// second loop for `fulfulled` results
return results.flatMap(result => result.value);

}

Expand Down

0 comments on commit d474443

Please sign in to comment.