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

Fix #2358 by recognizing props wrapped in $ReadOnly<> #2361

Merged
merged 1 commit into from Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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