diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index b9ea3789df..260d38c505 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -233,8 +233,9 @@ module.exports = { * @returns {Boolean} True if the prop is used, false if not. */ function isPropUsed(node, prop) { - for (let i = 0, l = node.usedPropTypes.length; i < l; i++) { - const usedProp = node.usedPropTypes[i]; + const usedPropTypes = node.usedPropTypes || []; + for (let i = 0, l = usedPropTypes.length; i < l; i++) { + const usedProp = usedPropTypes[i]; if ( prop.type === 'shape' || prop.name === '__ANY_KEY__' || @@ -896,7 +897,7 @@ module.exports = { } }, - JSXSpreadChild: function(node) { + JSXSpreadAttribute: function(node) { const component = components.get(utils.getParentComponent()); components.set(component ? component.node : node, { ignorePropsValidation: true @@ -958,6 +959,11 @@ module.exports = { stack.pop(); }, + ReturnStatement: function (node) { + const code = context.getSourceCode(); + return {code, node}; + }, + 'Program:exit': function() { stack = null; const list = components.list(); diff --git a/lib/util/Components.js b/lib/util/Components.js index 04b76e4c2f..1346fb9ef1 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -114,12 +114,8 @@ Components.prototype.list = function() { } const id = this._getId(this._list[j].node); list[j] = this._list[j]; - if (!list[j].usedPropTypes) { - list[j].usedPropTypes = []; - } - if (usedPropTypes[id]) { - list[j].usedPropTypes = (list[j].usedPropTypes).concat(usedPropTypes[id]); + list[j].usedPropTypes = (list[j].usedPropTypes || []).concat(usedPropTypes[id]); } } return list;