Skip to content

Commit a8f2fdb

Browse files
Diana SuvorovaDiana Suvorova
authored andcommitted
JSXSpreadAttribute instead of JSXSpreadChild
1 parent b7d8763 commit a8f2fdb

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ module.exports = {
233233
* @returns {Boolean} True if the prop is used, false if not.
234234
*/
235235
function isPropUsed(node, prop) {
236-
for (let i = 0, l = node.usedPropTypes.length; i < l; i++) {
237-
const usedProp = node.usedPropTypes[i];
236+
const usedPropTypes = node.usedPropTypes || [];
237+
for (let i = 0, l = usedPropTypes.length; i < l; i++) {
238+
const usedProp = usedPropTypes[i];
238239
if (
239240
prop.type === 'shape' ||
240241
prop.name === '__ANY_KEY__' ||
@@ -896,7 +897,7 @@ module.exports = {
896897
}
897898
},
898899

899-
JSXSpreadChild: function(node) {
900+
JSXSpreadAttribute: function(node) {
900901
const component = components.get(utils.getParentComponent());
901902
components.set(component ? component.node : node, {
902903
ignorePropsValidation: true
@@ -958,6 +959,11 @@ module.exports = {
958959
stack.pop();
959960
},
960961

962+
ReturnStatement: function (node) {
963+
const code = context.getSourceCode();
964+
return {code, node};
965+
},
966+
961967
'Program:exit': function() {
962968
stack = null;
963969
const list = components.list();

lib/util/Components.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,8 @@ Components.prototype.list = function() {
114114
}
115115
const id = this._getId(this._list[j].node);
116116
list[j] = this._list[j];
117-
if (!list[j].usedPropTypes) {
118-
list[j].usedPropTypes = [];
119-
}
120-
121117
if (usedPropTypes[id]) {
122-
list[j].usedPropTypes = (list[j].usedPropTypes).concat(usedPropTypes[id]);
118+
list[j].usedPropTypes = (list[j].usedPropTypes || []).concat(usedPropTypes[id]);
123119
}
124120
}
125121
return list;

0 commit comments

Comments
 (0)