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

Code before:

        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
            if (errorOnUnmatchedPattern) {
                await checkForIgnoredResults(currentSearch);
            }

            continue;
        }

        if (errorOnUnmatchedPattern) {

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

        }

    }

    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.
 * @returns {Promise<Array<string>>} The fully resolved file paths.

Review comment (security):
I think this should be outside `if (errorOnUnmatchedPattern) {}`, so that `errorOnUnmatchedPattern: false` does not suppress unexpected errors like file system errors. I denied permissions on `tools/internal-testers` directory, and then ran `eslint tools -f tap --no-error-on-unmatched-pattern`. It exits with 0 without linting anything. In eslintrc mode, the same command throws EPERM, which is I think better than silently ignoring the whole pattern.

Code after:

        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.
 * @returns {Promise<Array<string>>} The fully resolved file paths.
 * @throws {AllFilesIgnoredError} If there are no results due to an ignore pattern.
 * @throws {NoFilesFoundError} If no files matched the given patterns.
 */
async function findFiles({
    patterns,
    globInputPaths,