Skip to content

Commit

Permalink
Fix: only remove arrow before body in object-shorthand (fixes #11305) (
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and ilyavolodin committed Feb 1, 2019
1 parent fa2f370 commit 6567c4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/object-shorthand.js
Expand Up @@ -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]);
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/object-shorthand.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 6567c4f

Please sign in to comment.