Skip to content

Commit

Permalink
fix: rightNode LogicalExpression type add parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-bandi committed Mar 4, 2024
1 parent 88f7f09 commit 3d92145
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/jsx-no-leaked-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function ruleFixer(context, fixStrategy, fixer, reportedNode, leftNode, rightNod
return fixer.replaceText(reportedNode, `${newText} && ${alternateVal}`);
}

if (rightNode.type === 'ConditionalExpression') {
if (rightNode.type === 'ConditionalExpression' || rightNode.type === 'LogicalExpression') {
return fixer.replaceText(reportedNode, `${newText} && (${rightSideText})`);
}
if (rightNode.type === 'JSXElement') {
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 @@ -733,6 +733,24 @@ ruleTester.run('jsx-no-leaked-render', rule, {
}
`,
},
{
code: `
const Component = ({ connection, hasError, hasErrorUpdate}) => {
return <div>{connection && (hasError || hasErrorUpdate)}</div>
}
`,
options: [{ validStrategies: ['coerce'] }],
errors: [{
message: 'Potential leaked value that might cause unintentionally rendered values or rendering crashes',
line: 3,
column: 24,
}],
output: `
const Component = ({ connection, hasError, hasErrorUpdate}) => {
return <div>{!!connection && (hasError || hasErrorUpdate)}</div>
}
`,
},

// cases: ternary isn't valid if strategy is only "coerce"
{
Expand Down

0 comments on commit 3d92145

Please sign in to comment.