diff --git a/lib/rules/object-shorthand.js b/lib/rules/object-shorthand.js index ff6a51a4d17..31010f0e738 100644 --- a/lib/rules/object-shorthand.js +++ b/lib/rules/object-shorthand.js @@ -255,7 +255,7 @@ module.exports = { keyPrefix + keyText + sourceCode.text.slice(tokenBeforeParams.range[1], node.value.range[1]) ); } - const arrowToken = sourceCode.getTokens(node.value).find(token => token.value === "=>"); + const arrowToken = sourceCode.getTokenBefore(node.value.body, { filter: token => token.value === "=>" }); const tokenBeforeArrow = sourceCode.getTokenBefore(arrowToken); const hasParensAroundParameters = tokenBeforeArrow.type === "Punctuator" && tokenBeforeArrow.value === ")"; const oldParamText = sourceCode.text.slice(sourceCode.getFirstToken(node.value, node.value.async ? 1 : 0).range[0], tokenBeforeArrow.range[1]); diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index c52f43af089..19d2352909d 100644 --- a/tests/lib/rules/object-shorthand.js +++ b/tests/lib/rules/object-shorthand.js @@ -931,6 +931,14 @@ ruleTester.run("object-shorthand", rule, { parserOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, + { + + // https://github.com/eslint/eslint/issues/11305 + code: "({ key: (arg = () => {}) => {} })", + output: "({ key(arg = () => {}) {} })", + options: ["always", { avoidExplicitReturnArrows: true }], + errors: [METHOD_ERROR] + }, { code: ` function foo() {