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

no-unused-prop-types throwing error for destructured props #2424

Closed
woodenconsulting opened this issue Oct 1, 2019 · 10 comments · Fixed by #2428
Closed

no-unused-prop-types throwing error for destructured props #2424

woodenconsulting opened this issue Oct 1, 2019 · 10 comments · Fixed by #2428

Comments

@woodenconsulting
Copy link

woodenconsulting commented Oct 1, 2019

Sample Code

function myStatelessComponent(props) {
  const { test: { foo, bar } } = props;
  return (
    <div>
      {foo} {bar}
    </div>
  );
}

myStatelessComponent.propTypes = {
  test: PropTypes.shape({
    foo: PropTypes.string.isRequired,
    bar: PropTypes.string.isRequired
  }).isRequired
};

Issue

The linter erroneously throws on the test prop since only its descendants are used:
'test' PropType is defined but prop is never used react/no-unused-prop-types.

The issue first appeared with the 7.15.0 release published about 11 hours ago from the time of this writing. It's likely due to this commit.

Expected

The linter should not throw

@ljharb
Copy link
Member

ljharb commented Oct 1, 2019

cc @golopot

golopot added a commit to golopot/eslint-plugin-react that referenced this issue Oct 1, 2019
@golopot
Copy link
Contributor

golopot commented Oct 1, 2019

I cannot reproduce this. I added the test case in my fork branch and CI is passing. https://github.com/golopot/eslint-plugin-react/tree/eeee
https://travis-ci.org/golopot/eslint-plugin-react/builds/592117332

I have tried espree, babel-eslint, @typescript-eslint/parser, env: {mocha: true}, and declaring a local variable named test.

@ljharb
Copy link
Member

ljharb commented Oct 1, 2019

a PR with the test case would be appreciated.

@woodenconsulting can you provide any more info that would be helpful?

@woodenconsulting
Copy link
Author

woodenconsulting commented Oct 1, 2019

@golopot @ljharb I created a repo which reproduces the issue: https://github.com/woodenconsulting/epr-2424

Additional Notes

  • Unlike the code I first provided, the issue is only prevalent when I import the shape
  • The issue also goes away when I remove the eslint-config-airbnb plugin that we're using

I haven't had a chance to dig any further; however, for additional context this error is happening across several private repos where pinning to the prior version of eslint-plugin-react solves the issue (for now).

@ljharb
Copy link
Member

ljharb commented Oct 1, 2019

aha, that first bullet point seems like the trick.

@redbugz

This comment has been minimized.

@w33ble

This comment has been minimized.

@ljharb

This comment has been minimized.

@woodenconsulting
Copy link
Author

@golopot Your fix does indeed resolve the issue, thanks for the quick turn around! 💯

@w33ble
Copy link

w33ble commented Oct 2, 2019

Can confirm. Thanks for the fix and the notification. 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants