diff --git a/CHANGELOG.md b/CHANGELOG.md index 60a0643fa1..e0778fe32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,9 +16,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel * [`jsx-no-target-blank`]: avoid a crash with a non-string literal ([#2851][] @ljharb) * [`jsx-no-script-url`]: avoid crash with boolean `href` ([#2871][] @ljharb, @AriPerkkio) * [`no-typos`]: avoid crash with computed method name ([#2870][] @ljharb, @AriPerkkio) +* [`jsx-max-depth`]: avoid crash with childless jsx child ([#2869][] @ljharb, @AriPerkkio) [#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2871 [#2870]: https://github.com/yannickcr/eslint-plugin-react/issues/2870 +[#2869]: https://github.com/yannickcr/eslint-plugin-react/issues/2869 [#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851 [#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843 [#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840 diff --git a/lib/rules/jsx-max-depth.js b/lib/rules/jsx-max-depth.js index 2fe87b81c2..980efc57b1 100644 --- a/lib/rules/jsx-max-depth.js +++ b/lib/rules/jsx-max-depth.js @@ -52,7 +52,7 @@ module.exports = { function isLeaf(node) { const children = node.children; - return !children.length || !children.some(hasJSX); + return !children || children.length === 0 || !children.some(hasJSX); } function getDepth(node) { diff --git a/tests/lib/rules/jsx-max-depth.js b/tests/lib/rules/jsx-max-depth.js index 858443414c..2076efc403 100644 --- a/tests/lib/rules/jsx-max-depth.js +++ b/tests/lib/rules/jsx-max-depth.js @@ -107,6 +107,13 @@ ruleTester.run('jsx-max-depth', rule, { '};' ].join('\n'), options: [{max: 1}] + }, { + code: [ + 'export function MyComponent() {', + ' const A = <>{
};', + ' return
{A}
;', + '}' + ].join('\n') }], invalid: [{