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 false positive in no-unused-proptype #1218

Merged
merged 3 commits into from May 24, 2017
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
5 changes: 4 additions & 1 deletion lib/util/Components.js
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
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