Skip to content

Commit 932ab55

Browse files
authored
Merge pull request #44 from theprivileges/experimental-rest-property
fix: experimental rest property in no-unused-prop-types
2 parents 8d51b9d + 5d9d6f2 commit 932ab55

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/rules/no-unused-prop-types.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ const propsUsedInRedux = function (context) {
6666
const usedInReactRedux = context.getAncestors()
6767
.some(ancestor => belongsToReduxReact(ancestor, null, node));
6868
if (usedInReactRedux) {
69-
node.properties.forEach(prop => context.report(node, `exclude:${prop.key.name}`));
69+
node.properties.forEach((prop) => {
70+
if (prop.type === 'Property' && prop.key && prop.key.name) {
71+
return context.report(node, `exclude:${prop.key.name}`);
72+
} else if (prop.type === 'ExperimentalRestProperty' && prop.argument && prop.argument.name) {
73+
return context.report(node, `exclude:${prop.argument.name}`);
74+
}
75+
return undefined;
76+
});
7077
}
7178
},
7279
};

tests/lib/rules/no-unused-prop-types.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,41 @@ ruleTester.run('no-unused-prop-types', rule, {
9696
myProp: PropTypes.string.isRequired
9797
};
9898
99+
export default connect(mapStateToProps)(MyComponent);`,
100+
`const selectorFoo = (state) => ({isFetching: false, name: 'Foo', isDeleting: false, deltedId: ''});
101+
const selectorBar = (state) => ({ isFetching: false, name: 'Bar'});
102+
export const mapStateToProps = (state) => {
103+
const { isFetching: isFetchingFoo, ...restFoo } = selectorFoo(state);
104+
const { isFetching: isFeatchingBar, ...restBar } = selectorBar(state);
105+
return {
106+
isFetchingFoo,
107+
isFetchingBar,
108+
...restFoo,
109+
...restBar,
110+
};
111+
};
112+
export class MyComponent extends Component {
113+
render() {
114+
const {isFetchingFoo, name, isFetchingBar, isDeleting, deletedId} = this.props;
115+
return (
116+
<div>
117+
<span>{isFetchingFoo}</span>
118+
<span>{isDeleting}</span>
119+
<span>{isFetchingBar}</span>
120+
<span>{name}{deletedId}</span>
121+
</div>
122+
)
123+
}
124+
};
125+
126+
MyComponent.propTypes = {
127+
isFetchingFoo: PropTypes.bool.isRequired,
128+
isDeleting: PropTypes.bool.isRequired,
129+
deletedId: PropTypes.number.isRequired,
130+
name: Proptypes.string.isRequired,
131+
isFetchingBar: PropTypes.bool.isRequired,
132+
};
133+
99134
export default connect(mapStateToProps)(MyComponent);`,
100135
],
101136
invalid: [{

0 commit comments

Comments
 (0)