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 committed Jun 14, 2018
1 parent c82746c commit f53e781
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 @@ -103,12 +103,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 @@ -61,6 +61,19 @@ ruleTester.run('jsx-max-depth', rule, {
}, {
code: 'const foo = (x) => <div><em>{x}</em></div>;',
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 @@ -122,5 +135,22 @@ ruleTester.run('jsx-max-depth', rule, {
'</div>'
].join('\n'),
errors: [{message: 'Expected the depth of nested jsx elements to be <= 2, but found 3.'}]
}, {
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 f53e781

Please sign in to comment.