Skip to content

Commit

Permalink
Ignore rest spread when destructuring props (fixes #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Mar 30, 2015
1 parent 04cb124 commit 7830ee0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ module.exports = function(context) {
);
}

/**
* Checks if the prop is declared
* @param {String} name Name of the prop to check.
* @param {Object} component The component to process
* @returns {Boolean} True if the prop is declared, false if not.
*/
function hasSpreadOperator(node) {
var tokens = context.getTokens(node);
return tokens.length && tokens[0].value === '...';
}

/**
* Mark a prop type as used
* @param {ASTNode} node The AST node being marked.
Expand All @@ -107,9 +118,13 @@ module.exports = function(context) {
});
break;
case 'destructuring':
for (var i = 0, j = node.parent.parent.declarations[0].id.properties.length; i < j; i++) {
var properties = node.parent.parent.declarations[0].id.properties;
for (var i = 0, j = properties.length; i < j; i++) {
if (hasSpreadOperator(properties[i])) {
continue;
}
usedPropTypes.push({
name: node.parent.parent.declarations[0].id.properties[i].key.name,
name: properties[i].key.name,
node: node
});
}
Expand Down

0 comments on commit 7830ee0

Please sign in to comment.