Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ Components.prototype.list = function() {
component = this.get(node);
}
if (component) {
usedPropTypes[this._getId(component.node)] = (this._list[i].usedPropTypes || []).filter(function(propType) {
const newUsedProps = (this._list[i].usedPropTypes || []).filter(function(propType) {
return !propType.node || propType.node.kind !== 'init';
});

const componentId = this._getId(component.node);
usedPropTypes[componentId] = (usedPropTypes[componentId] || []).concat(newUsedProps);
}
}
// Assign used props in not confident components to the parent component
Expand Down
45 changes: 45 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,51 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// The next two test cases are related to: https://github.com/yannickcr/eslint-plugin-react/issues/1183
code: [
'export default function SomeComponent(props) {',
' const callback = () => {',
' props.a(props.b);',
' };',
'',
' const anotherCallback = () => {};',
'',
' return (',
' <SomeOtherComponent',
' name={props.c}',
' callback={callback}',
' />',
' );',
'}',
'',
'SomeComponent.propTypes = {',
' a: React.PropTypes.func.isRequired,',
' b: React.PropTypes.string.isRequired,',
' c: React.PropTypes.string.isRequired,',
'};'
].join('\n')
}, {
code: [
'export default function SomeComponent(props) {',
' const callback = () => {',
' props.a(props.b);',
' };',
'',
' return (',
' <SomeOtherComponent',
' name={props.c}',
' callback={callback}',
' />',
' );',
'}',
'',
'SomeComponent.propTypes = {',
' a: React.PropTypes.func.isRequired,',
' b: React.PropTypes.string.isRequired,',
' c: React.PropTypes.string.isRequired,',
'};'
].join('\n')
}
],

Expand Down