Skip to content

Commit 7830ee0

Browse files
committed
Ignore rest spread when destructuring props (fixes #46)
1 parent 04cb124 commit 7830ee0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/rules/prop-types.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ module.exports = function(context) {
8181
);
8282
}
8383

84+
/**
85+
* Checks if the prop is declared
86+
* @param {String} name Name of the prop to check.
87+
* @param {Object} component The component to process
88+
* @returns {Boolean} True if the prop is declared, false if not.
89+
*/
90+
function hasSpreadOperator(node) {
91+
var tokens = context.getTokens(node);
92+
return tokens.length && tokens[0].value === '...';
93+
}
94+
8495
/**
8596
* Mark a prop type as used
8697
* @param {ASTNode} node The AST node being marked.
@@ -107,9 +118,13 @@ module.exports = function(context) {
107118
});
108119
break;
109120
case 'destructuring':
110-
for (var i = 0, j = node.parent.parent.declarations[0].id.properties.length; i < j; i++) {
121+
var properties = node.parent.parent.declarations[0].id.properties;
122+
for (var i = 0, j = properties.length; i < j; i++) {
123+
if (hasSpreadOperator(properties[i])) {
124+
continue;
125+
}
111126
usedPropTypes.push({
112-
name: node.parent.parent.declarations[0].id.properties[i].key.name,
127+
name: properties[i].key.name,
113128
node: node
114129
});
115130
}

0 commit comments

Comments
 (0)