Skip to content

Commit 7f41894

Browse files
committed
[Fix] jsx-max-depth: avoid crash with childless jsx child
Fixes #2869
1 parent 4073d0e commit 7f41894

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1616
* [`jsx-no-target-blank`]: avoid a crash with a non-string literal ([#2851][] @ljharb)
1717
* [`jsx-no-script-url`]: avoid crash with boolean `href` ([#2871][] @ljharb, @AriPerkkio)
1818
* [`no-typos`]: avoid crash with computed method name ([#2870][] @ljharb, @AriPerkkio)
19+
* [`jsx-max-depth`]: avoid crash with childless jsx child ([#2869][] @ljharb, @AriPerkkio)
1920

2021
[#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2871
2122
[#2870]: https://github.com/yannickcr/eslint-plugin-react/issues/2870
23+
[#2869]: https://github.com/yannickcr/eslint-plugin-react/issues/2869
2224
[#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851
2325
[#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843
2426
[#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840

lib/rules/jsx-max-depth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
function isLeaf(node) {
5353
const children = node.children;
5454

55-
return !children.length || !children.some(hasJSX);
55+
return !children || children.length === 0 || !children.some(hasJSX);
5656
}
5757

5858
function getDepth(node) {

tests/lib/rules/jsx-max-depth.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ ruleTester.run('jsx-max-depth', rule, {
107107
'};'
108108
].join('\n'),
109109
options: [{max: 1}]
110+
}, {
111+
code: [
112+
'export function MyComponent() {',
113+
' const A = <>{<div />}</>;',
114+
' return <div>{A}</div>;',
115+
'}'
116+
].join('\n')
110117
}],
111118

112119
invalid: [{

0 commit comments

Comments
 (0)