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

Code before:
                    // {[x]: function(){}} should be written as {[x]() {}}
                    if (node.value.type === "FunctionExpression" ||
                        node.value.type === "ArrowFunctionExpression" &&
                        node.value.body.type === "BlockStatement" &&
                        AVOID_EXPLICIT_RETURN_ARROWS &&
                        !arrowsWithLexicalIdentifiers.has(node.value)
                    ) {
                        context.report({
                            node,
                            messageId: "expectedMethodShorthand",
                            fix: fixer => makeFunctionShorthand(fixer, node)
                        });
                    }
                } else if (node.value.type === "Identifier" && node.key.name === node.value.name && APPLY_TO_PROPS) {

                    // {x: x} should be written as {x}
                    context.report({
                        node,
                        messageId: "expectedPropertyShorthand",
                        fix(fixer) {
                            const lastKeyToken = sourceCode.getLastToken(node.key);

                            // x: /* */ x
                            if (sourceCode.commentsExistBetween(lastKeyToken, node.value)) {
                                return null;
                            }

                            return fixer.replaceText(node, node.value.name);
                        }
                    });
                } else if (node.value.type === "Identifier" && node.key.type === "Literal" && node.key.value === node.value.name && APPLY_TO_PROPS) {
                    if (AVOID_QUOTES) {
                        return;
                    }

                    // {"x": x} should be written as {x}
                    context.report({
                        node,
                        messageId: "expectedPropertyShorthand",
                        fix(fixer) {
                            const lastKeyToken = sourceCode.getLastToken(node.key);

                            // "x": /* */ x
                            if (sourceCode.commentsExistBetween(lastKeyToken, node.value)) {
                                return null;
                            }

                            return fixer.replaceText(node, node.value.name);
                        }
                    });
                }

Review comment (suggestion):
```suggestion

                            // x: /* */ x
                            if (sourceCode.commentsExistBetween(node.key, node.value)) {
                                return null;
                            }
```

We can use `node.key` directly.

Code after:
                    // {[x]: function(){}} should be written as {[x]() {}}
                    if (node.value.type === "FunctionExpression" ||
                        node.value.type === "ArrowFunctionExpression" &&
                        node.value.body.type === "BlockStatement" &&
                        AVOID_EXPLICIT_RETURN_ARROWS &&
                        !arrowsWithLexicalIdentifiers.has(node.value)
                    ) {
                        context.report({
                            node,
                            messageId: "expectedMethodShorthand",
                            fix: fixer => makeFunctionShorthand(fixer, node)
                        });
                    }
                } else if (node.value.type === "Identifier" && node.key.name === node.value.name && APPLY_TO_PROPS) {

                    // {x: x} should be written as {x}
                    context.report({
                        node,
                        messageId: "expectedPropertyShorthand",
                        fix(fixer) {

                            // x: /* */ x
                            // x: (/* */ x)
                            if (sourceCode.getCommentsInside(node).length > 0) {
                                return null;
                            }

                            return fixer.replaceText(node, node.value.name);
                        }
                    });
                } else if (node.value.type === "Identifier" && node.key.type === "Literal" && node.key.value === node.value.name && APPLY_TO_PROPS) {
                    if (AVOID_QUOTES) {
                        return;
                    }

                    // {"x": x} should be written as {x}
                    context.report({
                        node,
                        messageId: "expectedPropertyShorthand",
                        fix(fixer) {

                            // "x": /* */ x
                            // "x": (/* */ x)
                            if (sourceCode.getCommentsInside(node).length > 0) {
                                return null;
                            }

                            return fixer.replaceText(node, node.value.name);
                        }
                    });
                }