jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
8.99k stars 2.77k forks source link

react/prefer-read-only-props fails if using Flow's $ReadOnly<T> #2472

Closed osmestad closed 4 years ago

osmestad commented 5 years ago

If using Flow's object level annotation for read only (https://flow.org/en/docs/types/utilities/#toc-readonly), react/prefer-read-only-props rule will require each attribute in the object to be read-only too.

Example code that is read only:

props: $ReadOnly<{|
    dataTest?: string,
    className?: string,
  |}>,

This rule would require:

props: $ReadOnly<{|
    +dataTest?: string,
    +className?: string,
  |}>,

Which should not really be needed :-) I guess it might make the rule a bit more complex to implement though? (using Flow: 0.110.0, eslint-plugin-react: 7.16.0, eslint: 6.5.1)

osmestad commented 5 years ago

I think this is very similar issue to this one: #2358 (which was for the no-unused-prop-types rule)

ljharb commented 5 years ago

It seems like we should support this.

karolina-benitez commented 4 years ago

I'm going to give this a try