Eslint-plugin-react: forbid-foreign-prop-types should allow another component's propTypes in a propTypes definition

Created on 17 Jan 2018  路  5Comments  路  Source: yannickcr/eslint-plugin-react

Currently this results in a warning but shouldn't:

Button.propTypes = {
  ...Touchable.propTypes,
  color: PropTypes.string
}

The error message could also be improved to explain why using another component's propTypes is bad. For example: "Using propTypes from another component is not safe because they may be removed in production builds".

Comments via @gaearon on this issue: https://github.com/facebookincubator/create-react-app/pull/3818

enhancement help wanted

Most helpful comment

I wouldn't call it "softening"; just making it more accurate :-) but yes, I'm also open to that.

For an option name, allowInPropTypes? (since it's already a subset of "foreign propTypes")

All 5 comments

I think that by default, it definitely should warn on it; however, I'd be open to adding an option that explicitly allowed this case.

Something like allowPropTypesInPropTypes? Or is that too confusing?

allowPropTypesComposition?

Also, how do you feel about softening the error message a bit?

I wouldn't call it "softening"; just making it more accurate :-) but yes, I'm also open to that.

For an option name, allowInPropTypes? (since it's already a subset of "foreign propTypes")

Sounds good to me. I'll work on implementing this change.

Was this page helpful?
0 / 5 - 0 ratings