Repository: eslint/eslint
File: lib/linter/linter.js (JavaScript)

Code before:
     * Initialize the Linter.
     * @param {Object} [config] the config object
     * @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
     * @param {Array<string>} [config.flags] the feature flags to enable.
     * @param {"flat"|"eslintrc"} [config.configType="flat"] the type of config used.
     */
    constructor({ cwd, configType = "flat", flags = [] } = {}) {

        const processedFlags = [];

        flags.forEach(flag => {
            if (inactiveFlags.has(flag)) {
                const { description, replacedBy } = inactiveFlags.get(flag);

                if (typeof replacedBy === "undefined") {
                    throw new Error(`The flag '${flag}' is inactive: ${description}`);
                }

                if (typeof replacedBy === "string") {
                    processedFlags.push(replacedBy);
                }

                globalThis.process?.emitWarning?.(
                    `The flag '${flag}' is inactive: ${description}`,
                    `ESLintInactiveFlag_${flag}`
                );

                return;
            }

            if (!activeFlags.has(flag)) {
                throw new Error(`Unknown flag '${flag}'.`);
            }

            processedFlags.push(flag);
        });

        internalSlotsMap.set(this, {
            cwd: normalizeCwd(cwd),
            flags: processedFlags,
            lastConfigArray: null,
            lastSourceCode: null,
            lastSuppressedMessages: [],
            configType, // TODO: Remove after flat config conversion
            parserMap: new Map([["espree", espree]]),
            ruleMap: new Rules()
        });

        this.version = pkg.version;
    }


Review comment (suggestion):
I wasn't sure if `replacedBy` should be automatically included in the warning message (it isn't) or if we'll update the flag description to mention the new stable flag there.

Code after:
     * Initialize the Linter.
     * @param {Object} [config] the config object
     * @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
     * @param {Array<string>} [config.flags] the feature flags to enable.
     * @param {"flat"|"eslintrc"} [config.configType="flat"] the type of config used.
     */
    constructor({ cwd, configType = "flat", flags = [] } = {}) {

        const processedFlags = [];

        flags.forEach(flag => {
            if (inactiveFlags.has(flag)) {
                const inactiveFlagData = inactiveFlags.get(flag);
                const inactivityReason = getInactivityReasonMessage(inactiveFlagData);

                if (typeof inactiveFlagData.replacedBy === "undefined") {
                    throw new Error(`The flag '${flag}' is inactive: ${inactivityReason}`);
                }

                // if there's a replacement, enable it instead of original
                if (typeof inactiveFlagData.replacedBy === "string") {
                    processedFlags.push(inactiveFlagData.replacedBy);
                }

                globalThis.process?.emitWarning?.(
                    `The flag '${flag}' is inactive: ${inactivityReason}`,
                    `ESLintInactiveFlag_${flag}`
                );

                return;
            }

            if (!activeFlags.has(flag)) {
                throw new Error(`Unknown flag '${flag}'.`);
            }

            processedFlags.push(flag);
        });

        internalSlotsMap.set(this, {
            cwd: normalizeCwd(cwd),
            flags: processedFlags,
            lastConfigArray: null,
            lastSourceCode: null,
            lastSuppressedMessages: [],
            configType, // TODO: Remove after flat config conversion
            parserMap: new Map([["espree", espree]]),
            ruleMap: new Rules()
        });

        this.version = pkg.version;