Repository: eslint/eslint
File: lib/rules/complexity.js (JavaScript)

Code before:
        docs: {
            description: "Enforce a maximum cyclomatic complexity allowed in a program",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/complexity"
        },

        schema: [
            {
                oneOf: [
                    {
                        type: "integer",
                        minimum: 0
                    },
                    {
                        type: "object",
                        properties: {
                            maximum: {
                                type: "integer",
                                minimum: 0
                            },
                            max: {
                                type: "integer",
                                minimum: 0
                            },
                            variant: {
                                type: "string",
                                enum: ["classic", "modified"]
                            }
                        },
                        additionalProperties: false
                    }
                ]
            }
        ],

        messages: {
            complex: "{{name}} has a complexity of {{complexity}}. Maximum allowed is {{max}}."
        }
    },

    create(context) {
        const option = context.options[0];
        let THRESHOLD = 20;
        let VARIANT = "classic";

        if (typeof option === "object") {
            if (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) {
                THRESHOLD = option.maximum || option.max;
            }

            if (Object.hasOwn(option, "variant")) {

Review comment (bug):
By the way why can't we use the `default` property in JSONSchema? 
If I add e.g. `default: "classic"` here, all the tests fail with:

```
Error: Schema for rule complexity is invalid: default is ignored for: data1.variant
```

Would be nice to specify defaults at schema level

Code after:
        docs: {
            description: "Enforce a maximum cyclomatic complexity allowed in a program",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/complexity"
        },

        schema: [
            {
                oneOf: [
                    {
                        type: "integer",
                        minimum: 0
                    },
                    {
                        type: "object",
                        properties: {
                            maximum: {
                                type: "integer",
                                minimum: 0
                            },
                            max: {
                                type: "integer",
                                minimum: 0
                            },
                            variant: {
                                enum: ["classic", "modified"]
                            }
                        },
                        additionalProperties: false
                    }
                ]
            }
        ],

        messages: {
            complex: "{{name}} has a complexity of {{complexity}}. Maximum allowed is {{max}}."
        }
    },

    create(context) {
        const option = context.options[0];
        let THRESHOLD = 20;
        let VARIANT = "classic";

        if (typeof option === "object") {
            if (Object.hasOwn(option, "maximum") || Object.hasOwn(option, "max")) {
                THRESHOLD = option.maximum || option.max;
            }

            if (Object.hasOwn(option, "variant")) {
                VARIANT = option.variant;