Permalink
Browse files

Fix: only remove arrow before body in object-shorthand (fixes #11305) (

  • Loading branch information...
g-plane authored and ilyavolodin committed Feb 1, 2019
1 parent fa2f370 commit 6567c4f6665df85c3347388b29d8193cc8208d63
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/rules/object-shorthand.js
  2. +8 −0 tests/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]);
@@ -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() {

0 comments on commit 6567c4f

Please sign in to comment.