Skip to content

Commit

Permalink
Fix depth of JSX siblings in a JSXEpressionContainer
Browse files Browse the repository at this point in the history
Resolves #1762
  • Loading branch information
alexzherdev authored and ljharb committed Jun 14, 2018
1 parent a442067 commit de64a8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/jsx-max-depth.js
Expand Up @@ -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)) {
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/rules/jsx-max-depth.js
Expand Up @@ -81,6 +81,19 @@ ruleTester.run('jsx-max-depth', rule, {
].join('\n'),
parser: 'babel-eslint',
options: [{max: 2}]
}, {
code: `
const x = (
<tr>
<td>1</td>
<td>2</td>
</tr>
);
<tbody>
{x}
</tbody>
`,
options: [{max: 2}]
}],

invalid: [{
Expand Down Expand Up @@ -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 = (
<tr>
<td>1</td>
<td>2</td>
</tr>
);
<tbody>
{x}
</tbody>
`,
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.'}
]
}]
});

0 comments on commit de64a8b

Please sign in to comment.