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

Code before:
                });

                if (patternHasMatch) {
                    throw new AllFilesIgnoredError(patternsToReport[index]);
                }

                // otherwise no files were found
                if (errorOnUnmatchedPattern) {
                    throw new NoFilesFoundError(patternsToReport[index], globInputPaths);
                }

                index++;
            }
        }

    }

    // there were patterns that didn't match anything, tell the user
    if (errorOnUnmatchedPattern && missingPatterns.length) {
        throw new NoFilesFoundError(missingPatterns[0], globInputPaths);
    }


    return [
        ...results,
        ...globbyResults.map(filePath => ({
            filePath: path.resolve(filePath),
            ignored: false
        }))
    ];
}


/**
 * Checks whether a file exists at the given location
 * @param {string} resolvedPath A path from the CWD
 * @throws {Error} As thrown by `fs.statSync` or `fs.isFile`.
 * @returns {boolean} `true` if a file exists
 */
function fileExists(resolvedPath) {
    try {
        return fs.statSync(resolvedPath).isFile();
    } catch (error) {
        if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
            return false;
        }
        throw error;
    }
}

/**

Review comment (suggestion):
This first checks all unmatched patterns to see if there are some that match ignored files. I think we should always just check and report `patternsToCheck[0]`.

Code after:
async function checkForIgnoredResults({
    basePath,
    patterns,
    rawPatterns,
    patternsToCheck = patterns
}) {

    for (const pattern of patternsToCheck) {

        const patternHasMatch = await globMatch({
            basePath,
            pattern
        });

        if (patternHasMatch) {
            throw new AllFilesIgnoredError(
                rawPatterns[patterns.indexOf(pattern)]
            );
        }
    }

    // if we get here there are truly no matches
    throw new NoFilesFoundError(
        rawPatterns[patterns.indexOf(patternsToCheck[0])],
        true
    );
}

/**
 * Performs multiple glob searches in parallel.
 * @param {Object} options The options for this function.
 * @param {Map<string,GlobSearch>} options.searches
 *      An array of glob patterns to match.
 * @param {FlatConfigArray} options.configs The config array to use for
 *      determining what to ignore.
 * @param {boolean} options.errorOnUnmatchedPattern Determines if an
 *      unmatched glob pattern should throw an error.
 * @returns {Promise<Array<string>>} An array of matching file paths
 *      or an empty array if there are no matches.
 */
async function globMultiSearch({ searches, configs, errorOnUnmatchedPattern }) {

    /*
     * For convenience, we normalized the search map into an array of objects.
     * Next, we filter out all searches that have no patterns. This happens
     * primarily for the cwd, which is prepopulated in the searches map as an
     * optimization. However, if it has no patterns, it means all patterns
     * occur outside of the cwd and we can safely filter out that search.
     */
    const normalizedSearches = [...searches].map(
        ([basePath, { patterns, rawPatterns }]) => ({ basePath, patterns, rawPatterns })