Skip to content

Commit f53e781

Browse files
committed
Fix depth of JSX siblings in a JSXEpressionContainer
Resolves #1762
1 parent c82746c commit f53e781

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
@@ -103,12 +103,12 @@ module.exports = {
103103
}
104104

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

111-
baseDepth++;
112112
if (baseDepth > maxDepth) {
113113
report(node, baseDepth);
114114
} 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
@@ -61,6 +61,19 @@ ruleTester.run('jsx-max-depth', rule, {
6161
}, {
6262
code: 'const foo = (x) => <div><em>{x}</em></div>;',
6363
options: [{max: 2}]
64+
}, {
65+
code: `
66+
const x = (
67+
<tr>
68+
<td>1</td>
69+
<td>2</td>
70+
</tr>
71+
);
72+
<tbody>
73+
{x}
74+
</tbody>
75+
`,
76+
options: [{max: 2}]
6477
}],
6578

6679
invalid: [{
@@ -122,5 +135,22 @@ ruleTester.run('jsx-max-depth', rule, {
122135
'</div>'
123136
].join('\n'),
124137
errors: [{message: 'Expected the depth of nested jsx elements to be <= 2, but found 3.'}]
138+
}, {
139+
code: `
140+
const x = (
141+
<tr>
142+
<td>1</td>
143+
<td>2</td>
144+
</tr>
145+
);
146+
<tbody>
147+
{x}
148+
</tbody>
149+
`,
150+
options: [{max: 1}],
151+
errors: [
152+
{message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'},
153+
{message: 'Expected the depth of nested jsx elements to be <= 1, but found 2.'}
154+
]
125155
}]
126156
});

0 commit comments

Comments
 (0)