New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix propType detection inside class bodies #2115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks for the great fixes @drx! These helpers were extracted from two rules that had diverged slightly in how they detected propTypes, so it was tricky to de-duplicate them. It’s unfortunate that a few cases slipped through the cracks; they probably worked before but didn’t have test cases in the repo. |
## The devDependency [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) was updated from `7.12.2` to `7.12.3`. This version is **not covered** by your **current version range**. If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update. --- <details> <summary>Release Notes for v7.12.3</summary> <h3>Fixed</h3> <ul> <li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.3/docs/rules/jsx-indent.md"><code>jsx-indent</code></a>: Prevent crash on valueless props (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2120" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2120/hovercard">#2120</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=416773" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/jomasti">@jomasti</a>)</li> <li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.3/docs/rules/jsx-fragments.md"><code>jsx-fragments</code></a>: avoid crashing on self-closing fragments (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2113" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2113/hovercard">#2113</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=93752" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/alexzherdev">@alexzherdev</a>)</li> <li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.3/docs/rules/no-unused-prop-types.md"><code>no-unused-prop-types</code></a>: Fix propType detection inside class bodies (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2115" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2115/hovercard">#2115</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=233040" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/drx">@drx</a>)</li> <li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.3/docs/rules/no-unused-prop-types.md"><code>no-unused-prop-types</code></a>: fix issue with propTypes misclassifying props (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2111" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2111/hovercard">#2111</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=233040" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/drx">@drx</a>)</li> <li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.3/docs/rules/display-name.md"><code>display-name</code></a>: fix false positive for <code>React.memo</code> (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2109" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2109/hovercard">#2109</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=416773" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/jomasti">@jomasti</a>)</li> </ul> <h3>Changed</h3> <ul> <li>[Docs] add a missing comma in the JSON settings (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2117" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2117/hovercard">#2117</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=11673029" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/haideralsh">@haideralsh</a>)</li> <li>[Docs] update README to document React version detection (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2114" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2114/hovercard">#2114</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=7688231" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/mohsinulhaq">@mohsinulhaq</a>)</li> </ul> </details> <details> <summary>Commits</summary> <p>The new version differs by 14 commits.</p> <ul> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/2f5cec96eca70cfe579038c8b9a81ba5a6a88594"><code>2f5cec9</code></a> <code>Update CHANGELOG and bump version</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/096161a1c69c6d2f6ad0e8e1db7310fdf3061ede"><code>096161a</code></a> <code>Merge pull request #2120 from jomasti/issue-2119</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/9d3955adddc6e922e4a0714f3be0b9d0ba968d42"><code>9d3955a</code></a> <code>Prevent crash of jsx-indent rule</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/230c7e018b876a17336729f0f079f535227e3d0b"><code>230c7e0</code></a> <code>Merge pull request #2117 from haideralsh/patch-1</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/b4b0e7268b84593cbed6bc0ddf242629d0a30f70"><code>b4b0e72</code></a> <code>fix: add a missing in the JSON settings</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/d2aa2602043979dbfa79705dfad5865936f37ccb"><code>d2aa260</code></a> <code>Merge pull request #2115 from drx/class_body_prop_types</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/41974e5a89e527b79e97e097210a001de6e42788"><code>41974e5</code></a> <code>Fix propType detection inside class bodies</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/40f25659b9c801131bb0abed2030fdc54d88a074"><code>40f2565</code></a> <code>[Docs] update README to document React version detection</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/dd0757fbf7ab96770282a2a64c9b696856a47235"><code>dd0757f</code></a> <code>Merge pull request #2113 from alexzherdev/2112-fix-self-closing-fragments</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/e997f6c1bfcf62aee34274364f0766173ffc2829"><code>e997f6c</code></a> <code>[Fix] avoid crashing on self-closing fragments</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/b48b479716d684945d6286fde8e89b0c44653f38"><code>b48b479</code></a> <code>Merge pull request #2111 from drx/prop_types_class_properties</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/e15bafa35ae1d70983551e259879e3858e9e9347"><code>e15bafa</code></a> <code>[Fix] <code>no-unused-prop-types</code>: fix issue with propTypes misclassifying props</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/a86b3391deb53f20d10dc028c7b885f021f014b0"><code>a86b339</code></a> <code>Merge pull request #2109 from jomasti/issue-2105</code></li> <li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/5f9863e0856703c28e1e7cb9b1c78724dc12416b"><code>5f9863e</code></a> <code>Fix display-name false positive for React.memo</code></li> </ul> <p>See the <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/compare/c93cbc60b1847ef09c0b569ec997fb20dfca7c5a...2f5cec96eca70cfe579038c8b9a81ba5a6a88594">full diff</a></p> </details> <details> <summary>FAQ and help</summary> There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new). </details> --- Your [Greenkeeper](https://greenkeeper.io) bot 🌴
I investigated it a bit more and it turns out #2111 has more instances than just
ClassProperties
. A legit example is JSX render props:The
no-unused-prop-types
rule gives a warning thatnotAProp
is not used, because it thinksnotAProp
is a prop ofHello
.I added two more tests. The problem seems to occur in many cases involving functions being declared inside class bodies. The nice thing is that all of them have a
ClassBody
node as an ancestor so I changed the previous fix to look forClassBody
instead, which actually feels more like a proper fix.