Skip to content

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

@thany

Description

@thany

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions