Skip to content

Commit

Permalink
Merge pull request #1563 from justinanastos/fix/prop-types-union-flow…
Browse files Browse the repository at this point in the history
…type-1468

Fix crash when using Unions in flow propTypes
  • Loading branch information
ljharb committed Nov 22, 2017
2 parents 6829c5c + dd10851 commit df17cd4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ module.exports = {
return declarePropTypesForObjectTypeAnnotation(annotation, declaredPropTypes);
}

if (annotation.type === 'UnionTypeAnnotation') {
return true;
}

const typeNode = typeScope(annotation.id.name);

if (!typeNode) {
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ module.exports = {
return declarePropTypesForObjectTypeAnnotation(annotation, declaredPropTypes);
}

if (annotation.type === 'UnionTypeAnnotation') {
return true;
}

const typeNode = typeScope(annotation.id.name);

if (!typeNode) {
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,28 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'type PropsUnionA = {',
' a: string,',
' b?: void,',
'};',
'type PropsUnionB = {',
' a?: void,',
' b: string,',
'};',
'type Props = {',
' name: string,',
'} & (PropsUnionA | PropsUnionB);',
'class Hello extends React.Component {',
' props: Props;',
' render() {',
' const {name} = this.props;',
' return name;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'Card.propTypes = {',
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,28 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'type PropsUnionA = {',
' a: string,',
' b?: void,',
'};',
'type PropsUnionB = {',
' a?: void,',
' b: string,',
'};',
'type Props = {',
' name: string,',
'} & (PropsUnionA | PropsUnionB);',
'class Hello extends React.Component {',
' props: Props;',
' render() {',
' const {name} = this.props;',
' return name;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'Card.propTypes = {',
Expand Down

0 comments on commit df17cd4

Please sign in to comment.