Skip to content

Commit

Permalink
Merge pull request #1824 from alexzherdev/1762-jsx-max-depth-false-po…
Browse files Browse the repository at this point in the history
…sitive

Fix depth of JSX siblings in a JSXEpressionContainer
  • Loading branch information
ljharb committed Dec 27, 2018
2 parents a442067 + de64a8b commit 84be80a
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 84be80a

Please sign in to comment.