Repository: eslint/eslint
File: lib/config/rule-validator.js (JavaScript)

Code before:
    if (config.plugins && config.plugins[pluginName]) {
        const replacementRuleName = ruleReplacements.rules[ruleName];

        if (pluginName === "@" && replacementRuleName) {

            errorMessage = `${errorMessageHeader}: Rule "${ruleName}" was removed and replaced by "${replacementRuleName}".`;

        } else {

            errorMessage = `${errorMessageHeader}: Could not find "${ruleName}" in plugin "${pluginName}".`;

            // otherwise, let's see if we can find the rule name elsewhere
            for (const [otherPluginName, otherPlugin] of Object.entries(config.plugins)) {
                if (otherPlugin.rules && otherPlugin.rules[ruleName]) {
                    errorMessage += ` Did you mean "${otherPluginName}/${ruleName}"?`;
                    break;
                }
            }

        }

        // falls through to throw error
    }

    const finalError = errorMessage === "" ? error : new TypeError(errorMessage);

    throw finalError;
}

/**
 * The error type when a rule has an invalid `meta.schema`.
 */
class InvalidRuleOptionsSchemaError extends Error {

    /**
     * Creates a new instance.
     * @param {string} ruleId Id of the rule that has an invalid `meta.schema`.
     * @param {Error} processingError Error caught while processing the `meta.schema`.
     */
    constructor(ruleId, processingError) {
        super(
            `Error while processing options validation schema of rule '${ruleId}': ${processingError.message}`,
            { cause: processingError }
        );
        this.code = "ESLINT_INVALID_RULE_OPTIONS_SCHEMA";
    }
}

//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------

Review comment (suggestion):
This isn't necessary if we only set `errorMessage` before the `if` statements.

Code after:

        if (pluginName === "@" && replacementRuleName) {

            errorMessage = `${errorMessageHeader}: Rule "${ruleName}" was removed and replaced by "${replacementRuleName}".`;

        } else {

            errorMessage = `${errorMessageHeader}: Could not find "${ruleName}" in plugin "${pluginName}".`;

            // otherwise, let's see if we can find the rule name elsewhere
            for (const [otherPluginName, otherPlugin] of Object.entries(config.plugins)) {
                if (otherPlugin.rules && otherPlugin.rules[ruleName]) {
                    errorMessage += ` Did you mean "${otherPluginName}/${ruleName}"?`;
                    break;
                }
            }

        }

        // falls through to throw error
    }

    const error = new TypeError(errorMessage);

    if (errorMessage === missingPluginErrorMessage) {
        error.messageTemplate = "config-plugin-missing";
        error.messageData = { pluginName, ruleId };
    }

    throw error;
}

/**
 * The error type when a rule has an invalid `meta.schema`.
 */
class InvalidRuleOptionsSchemaError extends Error {

    /**
     * Creates a new instance.
     * @param {string} ruleId Id of the rule that has an invalid `meta.schema`.
     * @param {Error} processingError Error caught while processing the `meta.schema`.
     */
    constructor(ruleId, processingError) {
        super(
            `Error while processing options validation schema of rule '${ruleId}': ${processingError.message}`,
            { cause: processingError }
        );
        this.code = "ESLINT_INVALID_RULE_OPTIONS_SCHEMA";
    }
}