Skip to content

Commit

Permalink
Fix require-default-props rule when using Flow type from assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Jan 11, 2017
1 parent a33db3b commit 0e8a1be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ module.exports = {
switch (node.typeAnnotation.type) {
case 'GenericTypeAnnotation':
var annotation = resolveGenericTypeAnnotation(node.typeAnnotation);
properties = annotation ? annotation.properties : [];

if (annotation && annotation.id) {
annotation = findVariableByName(annotation.id.name);
}

properties = annotation ? (annotation.properties || []) : [];
break;

case 'UnionTypeAnnotation':
Expand Down
33 changes: 33 additions & 0 deletions tests/lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,39 @@ ruleTester.run('require-default-props', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
},
{
code: [
'import type ImportedProps from "fake";',
'type Props = ImportedProps;',
'function Hello(props: Props) {',
' return <div>Hello {props.name.firstname}</div>;',
'}'
].join('\n'),
parser: 'babel-eslint'
},
// don't error when variable is not in scope
{
code: [
'import type { ImportedType } from "fake";',
'type Props = ImportedType;',
'function Hello(props: Props) {',
' return <div>Hello {props.name.firstname}</div>;',
'}'
].join('\n'),
parser: 'babel-eslint'
},
// make sure error is not thrown with multiple assignments
{
code: [
'import type ImportedProps from "fake";',
'type NestedProps = ImportedProps;',
'type Props = NestedProps;',
'function Hello(props: Props) {',
' return <div>Hello {props.name.firstname}</div>;',
'}'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit 0e8a1be

Please sign in to comment.