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

Code before:
        const resultRules = new Map();
        const {
            configs,
            options: { cwd }
        } = privateMembers.get(this);

        /*
         * We can only accurately return rules meta information for linting results if the
         * results were created by this instance. Otherwise, the necessary rules data is
         * not available. So if the config array doesn't already exist, just throw an error
         * to let the user know we can't do anything here.
         */
        if (!configs) {
            throw createExtraneousResultsError();
        }

        for (const result of results) {

            /*
             * Normalize filename for <text>.
             */
            const filePath = result.filePath === "<text>"
                ? getPlaceholderPath(cwd) : result.filePath;
            const allMessages = result.messages.concat(result.suppressedMessages);

            for (const { ruleId } of allMessages) {

                /*
                 * All of the plugin and rule information is contained within the
                 * calculated config for the given file.
                 */
                const config = configs.getConfig(filePath);

                if (!config) {
                    throw createExtraneousResultsError();
                }
                const rule = getRuleFromConfig(ruleId, config);

                // ensure the rule exists
                if (!rule) {
                    throw new TypeError(`Could not find the rule "${ruleId}".`);
                }

                resultRules.set(ruleId, rule);
            }
        }

        return createRulesMeta(resultRules);
    }

    /**

Review comment (bug):
There may be an edge case here. getConfig returns undefined if a file is ignore by the configuration, so it doesn’t necessarily mean that the file wasn’t run in this instance. I think this will result in an error if the results contain a warning for a file that was ignored.

You can test this by passing in a file that is specifically ignored. 

Code after:
         */
        if (!configs) {
            throw createExtraneousResultsError();
        }

        for (const result of results) {

            /*
             * Normalize filename for <text>.
             */
            const filePath = result.filePath === "<text>"
                ? getPlaceholderPath(cwd) : result.filePath;
            const allMessages = result.messages.concat(result.suppressedMessages);

            for (const { ruleId } of allMessages) {
                if (!ruleId) {
                    continue;
                }

                /*
                 * All of the plugin and rule information is contained within the
                 * calculated config for the given file.
                 */
                const config = configs.getConfig(filePath);

                if (!config) {
                    throw createExtraneousResultsError();
                }
                const rule = getRuleFromConfig(ruleId, config);

                // ensure the rule exists
                if (!rule) {
                    throw new TypeError(`Could not find the rule "${ruleId}".`);
                }

                resultRules.set(ruleId, rule);
            }
        }

        return createRulesMeta(resultRules);
    }

    /**
     * Executes the current configuration on an array of file and directory names.
     * @param {string|string[]} patterns An array of file and directory names.
     * @returns {Promise<LintResult[]>} The results of linting the file patterns given.
     */
    async lintFiles(patterns) {
        if (!isNonEmptyString(patterns) && !isArrayOfNonEmptyString(patterns)) {
            throw new Error("'patterns' must be a non-empty string or an array of non-empty strings");
        }