Skip to content

Commit

Permalink
Fix #2358 - Recognize props wrapped in flow $ReadOnly<> utility type
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage committed Jul 28, 2019
1 parent 60d502d commit 0e70a3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/util/propTypes.js
Expand Up @@ -545,6 +545,16 @@ module.exports = function propTypesInstructions(context, components, utils) {
case 'IntersectionTypeAnnotation':
ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes);
break;
case 'GenericTypeAnnotation':
if (propTypes.id.name === '$ReadOnly') {
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(
propTypes.typeParameters.params[0],
declaredPropTypes
);
} else {
ignorePropsValidation = true;
}
break;
case null:
break;
default:
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -2710,6 +2710,17 @@ ruleTester.run('no-unused-prop-types', rule, {
};
`,
parser: parsers.BABEL_ESLINT
}, {
code: [
'type Props = $ReadOnly<{foo: number}>;',
'class Hello extends React.Component {',
' props: Props;',
' render () {',
' return <div>{this.props.foo}</div>;',
' }',
'}'
].join('\n'),
parser: parsers.BABEL_ESLINT
}, {
// issue #933
code: `
Expand Down Expand Up @@ -3656,6 +3667,20 @@ ruleTester.run('no-unused-prop-types', rule, {
errors: [
{message: '\'unused\' PropType is defined but prop is never used'}
]
}, {
code: [
'type Props = $ReadOnly<{unused: Object;}>;',
'class Hello extends React.Component {',
' props: Props;',
' render () {',
' return <div>Hello {this.props.firstname}</div>;',
' }',
'}'
].join('\n'),
parser: parsers.BABEL_ESLINT,
errors: [
{message: '\'unused\' PropType is defined but prop is never used'}
]
}, {
code: `
type PropsA = { a: string }
Expand Down

0 comments on commit 0e70a3a

Please sign in to comment.