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

Code before:
    }
};

/**
 * Creates a schema that always throws an error. Useful for warning
 * about eslintrc-style keys.
 * @param {string} key The eslintrc key to create a schema for.
 * @returns {ObjectPropertySchema} The schema.
 */
function createEslintrcSchema(key) {
    return {
        merge: "replace",
        validate() {
            throw new IncompatibleKeyError(key);
        }
    };
}

//-----------------------------------------------------------------------------
// Full schema
//-----------------------------------------------------------------------------

exports.flatConfigSchema = {

    // eslintrc-style keys that should warn
    env: createEslintrcSchema("env"),
    extends: createEslintrcSchema("extends"),
    globals: createEslintrcSchema("globals"),
    ignorePatterns: createEslintrcSchema("ignorePatterns"),
    noInlineConfig: createEslintrcSchema("noInlineConfig"),
    overrides: createEslintrcSchema("overrides"),
    parser: createEslintrcSchema("parser"),
    parserOptions: createEslintrcSchema("parserOptions"),
    reportUnusedDisableDirectives: createEslintrcSchema("reportUnusedDisableDirectives"),
    root: createEslintrcSchema("root"),

    // flat config keys
    settings: deepObjectAssignSchema,
    linterOptions: {
        schema: {
            noInlineConfig: booleanSchema,
            reportUnusedDisableDirectives: booleanSchema
        }
    },
    languageOptions: {
        schema: {
            ecmaVersion: ecmaVersionSchema,
            sourceType: sourceTypeSchema,
            globals: globalsSchema,
            parser: parserSchema,
            parserOptions: deepObjectAssignSchema

Review comment (refactor):
Even though we're unlikely to add any further keys, I might suggest a slight refactor here to remove the duplication of the key name, and not take up half the space in this schema with keys that we don't actually care about in the end:

```js
function rejectEslintrcKeySchema(key) {
    return {
        merge: "replace",
        validate() {
            throw new IncompatibleKeyError(key);
        }
    };
}

function rejectEslintrcKeySchemas(...keys) {
    return Object.fromEntries(keys.map(key => [key, rejectEslintrcKeySchema(key)]));
}

exports.flatConfigSchema = {

    ...rejectEslintrcKeySchemas("env", "extends", "globals", "ignorePatterns", "noInlineConfig", "overrides", "parser", "parserOptions", "reportUnusedDisableDirectives", "root"),

    settings: ...
    linterOptions: ...
...
```

Code after:
    }
};

/**
 * Creates a schema that always throws an error. Useful for warning
 * about eslintrc-style keys.
 * @param {string} key The eslintrc key to create a schema for.
 * @returns {ObjectPropertySchema} The schema.
 */
function createEslintrcErrorSchema(key) {
    return {
        merge: "replace",
        validate() {
            throw new IncompatibleKeyError(key);
        }
    };
}

const eslintrcKeys = [
    "env",
    "extends",
    "globals",
    "ignorePatterns",
    "noInlineConfig",
    "overrides",
    "parser",
    "parserOptions",
    "reportUnusedDisableDirectives",
    "root"
];

//-----------------------------------------------------------------------------
// Full schema
//-----------------------------------------------------------------------------

exports.flatConfigSchema = {

    // eslintrc-style keys that should always error
    ...Object.fromEntries(eslintrcKeys.map(key => [key, createEslintrcErrorSchema(key)])),

    // flat config keys
    settings: deepObjectAssignSchema,
    linterOptions: {
        schema: {
            noInlineConfig: booleanSchema,
            reportUnusedDisableDirectives: booleanSchema
        }
    },
    languageOptions: {
        schema: {
            ecmaVersion: ecmaVersionSchema,