Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #44 from theprivileges/experimental-rest-property
fix: experimental rest property in no-unused-prop-types
  • Loading branch information
ljharb committed Nov 2, 2019
2 parents 8d51b9d + 5d9d6f2 commit 932ab55
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/rules/no-unused-prop-types.js
Expand Up @@ -66,7 +66,14 @@ const propsUsedInRedux = function (context) {
const usedInReactRedux = context.getAncestors()
.some(ancestor => belongsToReduxReact(ancestor, null, node));
if (usedInReactRedux) {
node.properties.forEach(prop => context.report(node, `exclude:${prop.key.name}`));
node.properties.forEach((prop) => {
if (prop.type === 'Property' && prop.key && prop.key.name) {
return context.report(node, `exclude:${prop.key.name}`);
} else if (prop.type === 'ExperimentalRestProperty' && prop.argument && prop.argument.name) {
return context.report(node, `exclude:${prop.argument.name}`);
}
return undefined;
});
}
},
};
Expand Down
35 changes: 35 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -96,6 +96,41 @@ ruleTester.run('no-unused-prop-types', rule, {
myProp: PropTypes.string.isRequired
};
export default connect(mapStateToProps)(MyComponent);`,
`const selectorFoo = (state) => ({isFetching: false, name: 'Foo', isDeleting: false, deltedId: ''});
const selectorBar = (state) => ({ isFetching: false, name: 'Bar'});
export const mapStateToProps = (state) => {
const { isFetching: isFetchingFoo, ...restFoo } = selectorFoo(state);
const { isFetching: isFeatchingBar, ...restBar } = selectorBar(state);
return {
isFetchingFoo,
isFetchingBar,
...restFoo,
...restBar,
};
};
export class MyComponent extends Component {
render() {
const {isFetchingFoo, name, isFetchingBar, isDeleting, deletedId} = this.props;
return (
<div>
<span>{isFetchingFoo}</span>
<span>{isDeleting}</span>
<span>{isFetchingBar}</span>
<span>{name}{deletedId}</span>
</div>
)
}
};
MyComponent.propTypes = {
isFetchingFoo: PropTypes.bool.isRequired,
isDeleting: PropTypes.bool.isRequired,
deletedId: PropTypes.number.isRequired,
name: Proptypes.string.isRequired,
isFetchingBar: PropTypes.bool.isRequired,
};
export default connect(mapStateToProps)(MyComponent);`,
],
invalid: [{
Expand Down

0 comments on commit 932ab55

Please sign in to comment.