diff --git a/lib/rules/jsx-no-leaked-render.js b/lib/rules/jsx-no-leaked-render.js index 05f319edbf..b77cd576cc 100644 --- a/lib/rules/jsx-no-leaked-render.js +++ b/lib/rules/jsx-no-leaked-render.js @@ -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') { diff --git a/tests/lib/rules/jsx-no-leaked-render.js b/tests/lib/rules/jsx-no-leaked-render.js index 969c93635c..f5729bf059 100644 --- a/tests/lib/rules/jsx-no-leaked-render.js +++ b/tests/lib/rules/jsx-no-leaked-render.js @@ -733,6 +733,24 @@ ruleTester.run('jsx-no-leaked-render', rule, { } `, }, + { + code: ` + const Component = ({ connection, hasError, hasErrorUpdate}) => { + return
{connection && (hasError || hasErrorUpdate)}
+ } + `, + 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
{!!connection && (hasError || hasErrorUpdate)}
+ } + `, + }, // cases: ternary isn't valid if strategy is only "coerce" {