From de64a8b8ecae17980be1014fa981146eec657b80 Mon Sep 17 00:00:00 2001 From: Alex Zherdev Date: Wed, 13 Jun 2018 22:44:00 -0700 Subject: [PATCH] Fix depth of JSX siblings in a JSXEpressionContainer Resolves #1762 --- lib/rules/jsx-max-depth.js | 2 +- tests/lib/rules/jsx-max-depth.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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 = ( + + 1 + 2 + + ); + + {x} + + `, + options: [{max: 2}] }], invalid: [{ @@ -175,5 +188,22 @@ ruleTester.run('jsx-max-depth', rule, { {message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'}, {message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'} ] + }, { + code: ` + const x = ( + + 1 + 2 + + ); + + {x} + + `, + options: [{max: 1}], + errors: [ + {message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'}, + {message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'} + ] }] });