Skip to content
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

react/prop-types false positive when component is exported to a different name #2051

Closed
bdwain opened this issue Nov 19, 2018 · 6 comments
Closed
Assignees

Comments

@bdwain
Copy link

bdwain commented Nov 19, 2018

I have a component that is giving me false positives saying that a proptype is not defined.

'children' is missing in props validation react/prop-types

Here's an example

import React from 'react';
import PropTypes from 'prop-types';
import makeHoc from './make-hoc';
import selectors from './selectors';

class Foo extends React.Component {
  render() {
    return this.props.children;
  }
}

Foo.propTypes = {
  children: PropTypes.element.isRequired
};

export const Unconnected = Foo; //this line causes the issue
export default makeHoc(
  Foo,
  selectors
);

and it works if I change commented line above to this

export { Foo as Unconnected };

At first I thought #1958 was related but on second look it doesn't seem to be. I also tried downgrading to 7.10.0 and that didn't help.

I don't see anything wrong with that syntax, but please point out if I'm missing something. Thanks!

@ljharb
Copy link
Member

ljharb commented Nov 20, 2018

Certainly the as version is better, since it doesn't create an additional binding inside your module, but the = version should still work.

@bdwain
Copy link
Author

bdwain commented Nov 20, 2018

Agreed. But figured it was still a bug so I'd report it.

@alexzherdev
Copy link
Contributor

Hmm I pasted this entire example as a test for 7.11.1 and it passed

@ljharb
Copy link
Member

ljharb commented Dec 1, 2018

In that case let’s add the test case in a PR and close the issue. It’s possible this is a bug fixed in master but not yet released.

alexzherdev added a commit to alexzherdev/eslint-plugin-react that referenced this issue Dec 2, 2018
@alexzherdev
Copy link
Contributor

oh cool, according to the build in #2068 this does fail on ESLint 5.

@alexzherdev
Copy link
Contributor

Also, this has been filed before in #1957

ljharb pushed a commit to alexzherdev/eslint-plugin-react that referenced this issue Dec 3, 2018
@yannickcr yannickcr self-assigned this Jan 6, 2019
@ghost ghost mentioned this issue Jan 17, 2019
1 task
NimaSoroush pushed a commit to NimaSoroush/differencify that referenced this issue Feb 16, 2019
## The devDependency [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) was updated from `7.12.3` to `7.12.4`.
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.4</summary>

<h3>Fixed</h3>
<ul>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/no-unused-prop-types.md"><code>no-unused-prop-types</code></a>: avoid a crash (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2131" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2131/hovercard">#2131</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=45469" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/ljharb">@ljharb</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>: avoid further crashes from nonexistent nodes in unusedPropTypes (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2127" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2127/hovercard">#2127</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=45469" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/ljharb">@ljharb</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>: Read name of callee object (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/pull/2125" data-hovercard-type="pull_request" data-hovercard-url="/jsx-eslint/eslint-plugin-react/pull/2125/hovercard">#2125</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=817020" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/CrOrc">@CrOrc</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>: Ignore reassignments when matching props declarations with components (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2051" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2051/hovercard">#2051</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/1957" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/1957/hovercard">#1957</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=13209" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/yannickcr">@yannickcr</a>)</li>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>, <a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/no-unused-prop-types.md"><code>no-unused-prop-types</code></a>, <a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/require-default-props.md"><code>require-default-props</code></a>: Detect components with return statement in switch/case (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2118" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2118/hovercard">#2118</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=13209" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/yannickcr">@yannickcr</a>)</li>
</ul>
<h3>Changed</h3>
<ul>
<li><a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/prop-types.md"><code>prop-types</code></a>, <a href="/yannickcr/eslint-plugin-react/blob/v7.12.4/docs/rules/no-typos.md"><code>no-typos</code></a>: add passing test cases (<a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2123" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2123/hovercard">#2123</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2128" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2128/hovercard">#2128</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2136" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2136/hovercard">#2136</a>, <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/issues/2134" data-hovercard-type="issue" data-hovercard-url="/jsx-eslint/eslint-plugin-react/issues/2134/hovercard">#2134</a>, <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=45469" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://urls.greenkeeper.io/ljharb">@ljharb</a>)</li>
</ul>
</details>

<details>
<summary>Commits</summary>
<p>The new version differs by 10 commits.</p>
<ul>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/433cc3f6fea3a202426cf8ea568aa4bf3fe7a415"><code>433cc3f</code></a> <code>Update CHANGELOG and bump version</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/536bc35643eacfacbeb2391c8ee49903b97954dc"><code>536bc35</code></a> <code>[Tests] <code>prop-types</code>: add case from #2134</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/df7ffc1b43964e5589f4c24eb8eaf03e1cb9a437"><code>df7ffc1</code></a> <code>[Tests] <code>no-typos</code>: test case from #2136</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/c7e5f384821d273f27c71030951fb6f02da5cfc6"><code>c7e5f38</code></a> <code>[Tests] improve version detection tests.</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/2dd2277cc4166e368a1dd172cfcebedcf930c212"><code>2dd2277</code></a> <code>[Tests] <code>prop-types</code>: add now-passing test case</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/84652b6527161f651a671754fb5f619296c3654e"><code>84652b6</code></a> <code>[Fix] <code>no-unused-prop-types</code>: avoid a crash</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/58ed9e9716f74dbf758766a5ac22425be411181f"><code>58ed9e9</code></a> <code>[Fix] <code>prop-types</code>: avoid further crashes from nonexistent nodes in unusedPropTypes</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/7f7b96d155dcb43baa3f438aa7c4720f0aa94298"><code>7f7b96d</code></a> <code>[Fix] <code>prop-types</code>: Read name of callee object.</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/5fc50aa9238768674cf2a2ca1d9676be629a920a"><code>5fc50aa</code></a> <code>[Fix] Ignore reassignments when matching props declarations with components</code></li>
<li><a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/commit/ba80a4c01b1086f6fd1202ebc9c262fc5f05b65b"><code>ba80a4c</code></a> <code>[Fix] Detect components with return statement in switch/case</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/yannickcr/eslint-plugin-react/compare/2f5cec96eca70cfe579038c8b9a81ba5a6a88594...433cc3f6fea3a202426cf8ea568aa4bf3fe7a415">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 🌴
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants