Repository: eslint/eslint
File: lib/rules/no-object-constructor.js (JavaScript)

Code before:
        function needsParentheses(node) {
            let exprStatNode = node;

            while (exprStatNode && exprStatNode.type !== "ExpressionStatement") {
                exprStatNode = exprStatNode.parent;
            }
            if (exprStatNode && node.range[0] === exprStatNode.range[0]) {
                return true;
            }

            const prevToken = sourceCode.getTokenBefore(node);

            if (prevToken && isArrowToken(prevToken)) {
                return true;
            }

            return false;
        }

        /**
         * Reports on nodes where the `Object` constructor is called without arguments.
         * @param {ASTNode} node The node to evaluate.
         * @returns {void}
         */
        function check(node) {
            if (node.callee.name !== "Object" || node.arguments.length) {
                return;
            }

            const variable = getVariableByName(sourceCode.getScope(node), "Object");

            if (variable && variable.identifiers.length === 0) {
                const replacement = needsParentheses(node) ? "({})" : "{}";

                context.report({
                    node,
                    messageId: "preferLiteral",
                    suggest: [
                        {
                            messageId: "useLiteral",
                            data: { replacement },
                            fix: fixer => fixer.replaceText(node, replacement)
                        }
                    ]
                });
            }
        }

        return {
            CallExpression: check,
            NewExpression: check

Review comment (suggestion):
```suggestion
            if (node.callee.type !== "Identifier" || node.callee.name !== "Object" || node.arguments.length) {
```

It's always good to check the `type`, since other nodes may have the same property name.

Code after:
        },

        hasSuggestions: true,

        schema: [],

        messages: {
            preferLiteral: "The object literal notation {} is preferable.",
            useLiteral: "Replace with '{{replacement}}'."
        }
    },

    create(context) {

        const sourceCode = context.sourceCode;

        /**
         * Determines whether or not an object literal that replaces a specified node needs to be enclosed in parentheses.
         * @param {ASTNode} node The node to be replaced.
         * @returns {boolean} Whether or not parentheses around the object literal are required.
         */
        function needsParentheses(node) {
            if (isStartOfExpressionStatement(node)) {
                return true;
            }

            const prevToken = sourceCode.getTokenBefore(node);

            if (prevToken && isArrowToken(prevToken)) {
                return true;
            }

            return false;
        }

        /**
         * Reports on nodes where the `Object` constructor is called without arguments.
         * @param {ASTNode} node The node to evaluate.
         * @returns {void}
         */
        function check(node) {
            if (node.callee.type !== "Identifier" || node.callee.name !== "Object" || node.arguments.length) {
                return;
            }

            const variable = getVariableByName(sourceCode.getScope(node), "Object");

            if (variable && variable.identifiers.length === 0) {
                const replacement = needsParentheses(node) ? "({})" : "{}";

                context.report({