Repository: jsx-eslint/eslint-plugin-react (JavaScript)

Issue:
`react/jsx-max-depth` false positive
With the `react/jsx-max-depth` rule enabled with default settings, I get a false positive with the following code:

```jsx
const TABLE_HEADERS = (
  <tr className='tasks-table__header-row'>
    <th className='tasks-table__header' />
    <th className='tasks-table__header'>{'Title'}</th>
    <th className='tasks-table__header' />
    <th className='tasks-table__header'>{'Estimate'}</th>
    <th className='tasks-table__header' />
    <th className='tasks-table__header'>{'Priority'}</th>
    <th className='tasks-table__header'>{'Timeframe'}</th>
    <th className='tasks-table__header' />
  </tr>
);
```

It reports:

```
  12:5  error  Expected the depth of nested jsx elements to be <= 2, but found 4   react/jsx-max-depth
  13:5  error  Expected the depth of nested jsx elements to be <= 2, but found 5   react/jsx-max-depth
  14:5  error  Expected the depth of nested jsx elements to be <= 2, but found 6   react/jsx-max-depth
  15:5  error  Expected the depth of nested jsx elements to be <= 2, but found 7   react/jsx-max-depth
  16:5  error  Expected the depth of nested jsx elements to be <= 2, but found 8   react/jsx-max-depth
  17:5  error  Expected the depth of nested jsx elements to be <= 2, but found 9   react/jsx-max-depth
  18:5  error  Expected the depth of nested jsx elements to be <= 2, but found 10  react/jsx-max-depth
  19:5  error  Expected the depth of nested jsx elements to be <= 2, but found 11  react/jsx-max-depth
```

It appears that maybe there's a false positive when a tag is self-closing, but I'm also confused as to why it registers 4 instead of 2 on line 12, which maps to the first `th` tag above.


Discussion:
In what context is TABLE_HEADERS used?
It looks like this:

```jsx
render() {
  return (
    <div>
      <table>
        <thead>{TABLE_HEADERS}</thead>
      </table>
    </div>
  );
}
```

I realized that the 4 instead of 2 bit was because it measures the nesting of all elements in the file, regardless of indirection, but still the count going up is a little odd.
Indeed, the `tr` there is at the 4th level, and the `th`'s each on the 5th.

I don't think being self-closing matters, or else the lines with two non-self-closing `th` tags in a row wouldn't have incremented the count - but there's definitely a bug here with the reported count in the error message.



Patch:
diff --git a/lib/rules/jsx-max-depth.js b/lib/rules/jsx-max-depth.js
index 02de21ef03..149d4c7368 100644
--- a/lib/rules/jsx-max-depth.js
+++ b/lib/rules/jsx-max-depth.js
@@ -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)) {


Test patch:
diff --git a/tests/lib/rules/jsx-max-depth.js b/tests/lib/rules/jsx-max-depth.js
index 2519b54dbe..62b557e3da 100644
--- a/tests/lib/rules/jsx-max-depth.js
+++ b/tests/lib/rules/jsx-max-depth.js
@@ -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: [{
@@ -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.'}
+    ]
   }]
 });