Skip to content

Commit 8863dfa

Browse files
committed
Fix destructured arguments to be assigned to the parent stateless component (fixes #698)
1 parent 57c6ccf commit 8863dfa

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/util/Components.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ Components.prototype.list = function() {
9898
component = this.get(node);
9999
}
100100
if (component) {
101-
usedPropTypes[this._getId(component.node)] = this._list[i].usedPropTypes;
101+
usedPropTypes[this._getId(component.node)] = (this._list[i].usedPropTypes || []).filter(function(propType) {
102+
return propType.node.kind !== 'init';
103+
});
102104
}
103105
}
104106
// Assign used props in not confident components to the parent component

tests/lib/rules/prop-types.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,17 @@ ruleTester.run('prop-types', rule, {
22212221
errors: [
22222222
{message: '\'name.constructor.firstname\' is missing in props validation'}
22232223
]
2224+
}, {
2225+
code: [
2226+
'function SomeComponent({bar}) {',
2227+
' function f({foo}) {}',
2228+
' return <div className={f()}>{bar}</div>;',
2229+
'}'
2230+
].join('\n'),
2231+
parserOptions: parserOptions,
2232+
errors: [
2233+
{message: '\'bar\' is missing in props validation'}
2234+
]
22242235
}
22252236
]
22262237
});

0 commit comments

Comments
 (0)