Skip to content

Commit 730bac9

Browse files
developer-bandiljharb
authored andcommitted
[Fix] jsx-no-leaked-render: prevent wrongly adding parens
1 parent b7780ce commit 730bac9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`jsx-no-leaked-render`]: prevent wrongly adding parens ([#3700][] @developer-bandi)
10+
11+
[#3700]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3700
12+
813
## [7.34.0] - 2024.03.03
914

1015
### Added

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)