Skip to content

Commit 3d92145

Browse files
fix: rightNode LogicalExpression type add parentheses
1 parent 88f7f09 commit 3d92145

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/rules/jsx-no-leaked-render.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function ruleFixer(context, fixStrategy, fixer, reportedNode, leftNode, rightNod
7979
return fixer.replaceText(reportedNode, `${newText} && ${alternateVal}`);
8080
}
8181

82-
if (rightNode.type === 'ConditionalExpression') {
82+
if (rightNode.type === 'ConditionalExpression' || rightNode.type === 'LogicalExpression') {
8383
return fixer.replaceText(reportedNode, `${newText} && (${rightSideText})`);
8484
}
8585
if (rightNode.type === 'JSXElement') {

tests/lib/rules/jsx-no-leaked-render.js

+18
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,24 @@ ruleTester.run('jsx-no-leaked-render', rule, {
733733
}
734734
`,
735735
},
736+
{
737+
code: `
738+
const Component = ({ connection, hasError, hasErrorUpdate}) => {
739+
return <div>{connection && (hasError || hasErrorUpdate)}</div>
740+
}
741+
`,
742+
options: [{ validStrategies: ['coerce'] }],
743+
errors: [{
744+
message: 'Potential leaked value that might cause unintentionally rendered values or rendering crashes',
745+
line: 3,
746+
column: 24,
747+
}],
748+
output: `
749+
const Component = ({ connection, hasError, hasErrorUpdate}) => {
750+
return <div>{!!connection && (hasError || hasErrorUpdate)}</div>
751+
}
752+
`,
753+
},
736754

737755
// cases: ternary isn't valid if strategy is only "coerce"
738756
{

0 commit comments

Comments
 (0)