Skip to content

Commit 2365926

Browse files
committed
Fix depth of JSX siblings in a JSXEpressionContainer
Resolves #1762
1 parent 95d3c3f commit 2365926

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/rules/jsx-max-depth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ module.exports = {
102102
}
103103

104104
function checkDescendant(baseDepth, children) {
105+
baseDepth++;
105106
children.forEach(node => {
106107
if (!hasJSX(node)) {
107108
return;
108109
}
109110

110-
baseDepth++;
111111
if (baseDepth > maxDepth) {
112112
report(node, baseDepth);
113113
} else if (!isLeaf(node)) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ ruleTester.run('jsx-max-depth', rule, {
8181
].join('\n'),
8282
parser: 'babel-eslint',
8383
options: [{max: 2}]
84+
}, {
85+
code: `
86+
const x = (
87+
<tr>
88+
<td>1</td>
89+
<td>2</td>
90+
</tr>
91+
);
92+
<tbody>
93+
{x}
94+
</tbody>
95+
`,
96+
options: [{max: 2}]
8497
}],
8598

8699
invalid: [{
@@ -175,5 +188,22 @@ ruleTester.run('jsx-max-depth', rule, {
175188
{message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'},
176189
{message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'}
177190
]
191+
}, {
192+
code: `
193+
const x = (
194+
<tr>
195+
<td>1</td>
196+
<td>2</td>
197+
</tr>
198+
);
199+
<tbody>
200+
{x}
201+
</tbody>
202+
`,
203+
options: [{max: 1}],
204+
errors: [
205+
{message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'},
206+
{message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'}
207+
]
178208
}]
179209
});

0 commit comments

Comments
 (0)