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

forbid-prop-types: depends on how objectOf is imported #2662

Closed
thany opened this issue Jun 8, 2020 · 5 comments
Closed

forbid-prop-types: depends on how objectOf is imported #2662

thany opened this issue Jun 8, 2020 · 5 comments

Comments

@thany
Copy link

thany commented Jun 8, 2020

Consider the following rule:

"react/forbid-prop-types": [ "error", { "forbid": [ "any", "object", "objectOf", "array" ] } ],

This would yield an error, which is correct:

import PropTypes from 'prop-types';

AwesomeComponent.propTypes = {
  foo: PropTypes.objectOf(PropTypes.any)
};

This would also yield an error, which is correct:

import { any } from 'prop-types';

AwesomeComponent.propTypes = {
  foo: any
};

This should yield an error, but doesn't:

import { objectOf, any } from 'prop-types';

AwesomeComponent.propTypes = {
  foo: objectOf(any)
};

This is slightly related to #2657 where any should be blocked in the above example, but isn't. But the bug I'm describing here, is that objectOf only yields an error if it's imported as part of a default import, where it doesn't yield an error when imported as a destructured import. Strangely though, any is not affected by this phenomenon, only objectOf is.

I'm on eslint-plugin-react 7.19.0, as part of react-scripts 3.4.1.

@ljharb
Copy link
Member

ljharb commented Jun 8, 2020

Please confirm with v7.20.0, but otherwise this is definitely a bug.

@thany
Copy link
Author

thany commented Jun 9, 2020

Just tried, and this seems to happen in 7.20.0 as well.

ljharb added a commit to ljharb/eslint-plugin-react that referenced this issue Jun 12, 2020
@ljharb
Copy link
Member

ljharb commented Jun 12, 2020

I've gotten a failing test written, but haven't been able to quickly figure out how to fix it. A PR would be most appreciated.

@ajkovar
Copy link
Contributor

ajkovar commented Jun 15, 2020

Nice test demo. I think I might have a fix in mind for it this nobody minds me taking a crack at it.

@ljharb
Copy link
Member

ljharb commented Jun 15, 2020

Please do!

ajkovar added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 16, 2020
ljharb added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 16, 2020
ajkovar added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 16, 2020
ajkovar added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 16, 2020
ajkovar added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 16, 2020
ajkovar added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 16, 2020
ajkovar added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 23, 2020
ljharb added a commit to ajkovar/eslint-plugin-react that referenced this issue Jun 27, 2020
@ljharb ljharb closed this as completed in 997a99f Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants