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

Code before:
                    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):
how about if we give a fix here through appending the comment before or after the property something like:
```js
var x = {
a /* comment */: a,
b
}
```
can be fixed to
```js
var x = {
/* comment */ a,
b
}
```
or

```js
var x = {
a, /* comment */ 
b
}
```

Code after:
                    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);
                        }
                    });
                }
            }