Repository: eslint/eslint
File: lib/rules/no-inner-declarations.js (JavaScript)

Code before:
        schema: [
            {
                enum: ["functions", "both"]
            },
            {
                type: "object",
                properties: {
                    legacy: {
                        type: "boolean",
                        default: false
                    }
                },
                additionalProperties: false
            }
        ],

        messages: {
            moveDeclToRoot: "Move {{type}} declaration to {{body}} root."
        }
    },

    create(context) {

        const sourceCode = context.sourceCode;
        const programAst = sourceCode.ast;
        const ecmaVersion = context.languageOptions.ecmaVersion || 6;
        const options = context.options[1];
        const legacy = options && options.legacy || false;

        /**
         * Check whether the linted file is in the strict mode or not.
         * @returns {boolean} `true` if code is in strict mode.
         */
        function isStrictCode() {
            const node = programAst.body[0];

            return (node.type === "ExpressionStatement" && node.expression.type === "Literal" && node.expression.value === "use strict");
        }

        /**
         * Ensure that a given node is at a program or function body's root.
         * @param {ASTNode} node Declaration node to check.
         * @returns {void}
         */
        function check(node) {
            const parent = node.parent;

            if (
                parent.type === "BlockStatement" && validBlockStatementParent.has(parent.parent.type)
            ) {
                return;

Review comment (suggestion):
I think we are really checking for undefined here?
```suggestion
        const ecmaVersion = context.languageOptions.ecmaVersion ?? 6;
```

Code after:
        schema: [
            {
                enum: ["functions", "both"]
            },
            {
                type: "object",
                properties: {
                    blockScopedFunctions: {
                        enum: ["allow", "disallow"]
                    }
                },
                additionalProperties: false
            }
        ],

        messages: {
            moveDeclToRoot: "Move {{type}} declaration to {{body}} root."
        }
    },

    create(context) {

        const sourceCode = context.sourceCode;
        const ecmaVersion = context.languageOptions.ecmaVersion;
        const blockScopedFunctions = context.options[1]?.blockScopedFunctions ?? "allow";

        /**
         * Ensure that a given node is at a program or function body's root.
         * @param {ASTNode} node Declaration node to check.
         * @returns {void}
         */
        function check(node) {
            const parent = node.parent;

            if (
                parent.type === "BlockStatement" && validBlockStatementParent.has(parent.parent.type)
            ) {
                return;
            }

            if (validParent.has(parent.type)) {
                return;
            }

            context.report({
                node,
                messageId: "moveDeclToRoot",
                data: {
                    type: (node.type === "FunctionDeclaration" ? "function" : "variable"),
                    body: getAllowedBodyDescription(node)
                }