Skip to content

Commit

Permalink
[Fix] jsx-no-leaked-render: removing parentheses for conditionals f…
Browse files Browse the repository at this point in the history
…ixed
  • Loading branch information
akulsr0 committed Dec 5, 2022
1 parent a60f04d commit 63b7785
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/jsx-no-leaked-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function ruleFixer(context, fixStrategy, fixer, reportedNode, leftNode, rightNod
return `${getIsCoerceValidNestedLogicalExpression(node) ? '' : '!!'}${nodeText}`;
}).join(' && ');

if (rightNode.type === 'ConditionalExpression') {
return fixer.replaceText(reportedNode, `${newText} && (${rightSideText})`);
}
return fixer.replaceText(reportedNode, `${newText} && ${rightSideText}`);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/jsx-no-leaked-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,5 +829,23 @@ ruleTester.run('jsx-no-leaked-render', rule, {
column: 24,
}],
},
{
code: `
const MyComponent = () => {
return <div>{maybeObject && (isFoo ? <Aaa /> : <Bbb />)}</div>
}
`,
output: `
const MyComponent = () => {
return <div>{!!maybeObject && (isFoo ? <Aaa /> : <Bbb />)}</div>
}
`,
options: [{ validStrategies: ['coerce'] }],
errors: [{
message: 'Potential leaked value that might cause unintentionally rendered values or rendering crashes',
line: 3,
column: 24,
}],
},
]),
});

0 comments on commit 63b7785

Please sign in to comment.