diff --git a/lib/rules/jsx-max-depth.js b/lib/rules/jsx-max-depth.js index 02de21ef03..149d4c7368 100644 --- a/lib/rules/jsx-max-depth.js +++ b/lib/rules/jsx-max-depth.js @@ -102,12 +102,12 @@ module.exports = { } function checkDescendant(baseDepth, children) { + baseDepth++; children.forEach(node => { if (!hasJSX(node)) { return; } - baseDepth++; if (baseDepth > maxDepth) { report(node, baseDepth); } else if (!isLeaf(node)) { diff --git a/tests/lib/rules/jsx-max-depth.js b/tests/lib/rules/jsx-max-depth.js index 2519b54dbe..62b557e3da 100644 --- a/tests/lib/rules/jsx-max-depth.js +++ b/tests/lib/rules/jsx-max-depth.js @@ -81,6 +81,19 @@ ruleTester.run('jsx-max-depth', rule, { ].join('\n'), parser: 'babel-eslint', options: [{max: 2}] + }, { + code: ` + const x = ( +