Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dora1998 committed Apr 14, 2023
1 parent 2662e6e commit 620311f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/eslint-plugin/src/util/getWrappingFixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,9 @@ function isObjectExpressionInOneLineReturn(
node: TSESTree.Node,
innerNode: TSESTree.Node,
): boolean {
if (
return (
node.parent?.type === AST_NODE_TYPES.ArrowFunctionExpression &&
node.parent?.body === node &&
node.parent.body === node &&
innerNode.type === AST_NODE_TYPES.ObjectExpression
) {
return true;
}

return false;
);
}
17 changes: 17 additions & 0 deletions packages/eslint-plugin/tests/util/getWrappingFixer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,22 @@ ruleTester.run('getWrappingFixer - removeFunctionRule', removeFunctionRule, {
errors: [{ messageId: 'removeFunction' }],
output: '() => ({ x: "wrapObject" })',
},

// shouldn't add parens when not necessary
{
code: 'const a = fn({ x: "wrapObject" })',
errors: [{ messageId: 'removeFunction' }],
output: 'const a = { x: "wrapObject" }',
},
{
code: '() => fn("string")',
errors: [{ messageId: 'removeFunction' }],
output: '() => "string"',
},
{
code: '(params = fn({ x: "wrapObject" })) => "string"',
errors: [{ messageId: 'removeFunction' }],
output: '(params = { x: "wrapObject" }) => "string"',
},
],
});

0 comments on commit 620311f

Please sign in to comment.