Repository: eslint/eslint
File: lib/eslint/eslint-helpers.js (JavaScript)

Code before:
                configs,
                errorOnUnmatchedPattern
            })
        )
    );

    const filePaths = [];

    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;
            }

            // if the are no results we need to check for ignored files
            await checkForIgnoredResults({
                ...currentSearch,
                errorOnUnmatchedPattern
            });
            continue;
        }

        // if we make it here then there was an error
        const error = result.reason;

        // unexpected errors should be re-thrown
        if (!error.basePath) {
            throw error;
        }

        await checkForIgnoredResults({
            ...currentSearch,
            patternsToCheck: error.patternsToCheck,
            errorOnUnmatchedPattern
        });

    }

    return [...new Set(filePaths)];

}

/**
 * Finds all files matching the options specified.

Review comment (bug):
I think this should be removed.

With `errorOnUnmatchedPattern = true`, `globSearch` will either return some results or throw `UnmatchedSearchPatternsError`, so either way `globMultiSearch` will never fall into this branch?

With `errorOnUnmatchedPattern = false`, this causes a different behavior than that of eslintrc in regard to patterns that match only ignored files.

For example, run:

```
eslint "tools/*.js" --ignore-pattern "tools/*.js" --no-error-on-unmatched-pattern
```

In eslintrc mode, this exits with 0, meaning that `--no-error-on-unmatched-pattern` applies to patterns that match only ignored files too.

In flat config mode (current iteration of this PR), the same command throws an error:

```
Oops! Something went wrong! :(

ESLint: 8.26.0

You are linting "tools/*.js", but all of the files matching the glob pattern "tools/*.js" are ignored.
```

Code after:

    const filePaths = [];

    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;
        }

        // if we make it here then there was an error
        const error = result.reason;

        // unexpected errors should be re-thrown
        if (!error.basePath) {
            throw error;
        }

        if (errorOnUnmatchedPattern) {

            await checkForIgnoredResults({
                ...currentSearch,
                patternsToCheck: error.patternsToCheck
            });

        }

    }

    return [...new Set(filePaths)];

}

/**
 * Finds all files matching the options specified.
 * @param {Object} args The arguments objects.
 * @param {Array<string>} args.patterns An array of glob patterns.
 * @param {boolean} args.globInputPaths true to interpret glob patterns,
 *      false to not interpret glob patterns.
 * @param {string} args.cwd The current working directory to find from.
 * @param {FlatConfigArray} args.configs The configs for the current run.
 * @param {boolean} args.errorOnUnmatchedPattern Determines if an unmatched pattern
 *      should throw an error.