Skip to content

Commit 6b239a7

Browse files
authored
Merge pull request #1939 from alexzherdev/prop-types-tests
Additional cases for prop-types and no-unused-prop-types
2 parents d7ba7c6 + 2d28512 commit 6b239a7

File tree

5 files changed

+382
-38
lines changed

5 files changed

+382
-38
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module.exports = {
146146
function mustBeValidated(component) {
147147
return Boolean(
148148
component &&
149-
!component.ignorePropsValidation
149+
!component.ignoreUnusedPropTypesValidation
150150
);
151151
}
152152

@@ -397,7 +397,7 @@ module.exports = {
397397

398398
const component = components.get(utils.getParentComponent());
399399
const usedPropTypes = component && component.usedPropTypes || [];
400-
let ignorePropsValidation = component && component.ignorePropsValidation || false;
400+
let ignoreUnusedPropTypesValidation = component && component.ignoreUnusedPropTypesValidation || false;
401401

402402
switch (type) {
403403
case 'direct':
@@ -414,7 +414,7 @@ module.exports = {
414414
case 'destructuring':
415415
for (let k = 0, l = (properties || []).length; k < l; k++) {
416416
if (hasSpreadOperator(properties[k]) || properties[k].computed) {
417-
ignorePropsValidation = true;
417+
ignoreUnusedPropTypesValidation = true;
418418
break;
419419
}
420420
const propName = getKeyValue(properties[k]);
@@ -441,7 +441,7 @@ module.exports = {
441441

442442
components.set(component ? component.node : node, {
443443
usedPropTypes: usedPropTypes,
444-
ignorePropsValidation: ignorePropsValidation
444+
ignoreUnusedPropTypesValidation: ignoreUnusedPropTypesValidation
445445
});
446446
}
447447

lib/rules/prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ module.exports = {
191191
return true;
192192
}
193193
// Consider every children as declared
194-
if (propType.children === true) {
194+
if (propType.children === true || propType.containsSpread) {
195195
return true;
196196
}
197197
if (propType.acceptedProperties) {

lib/util/propTypes.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
143143
}
144144
});
145145

146-
// nested object type spread means we need to ignore/accept everything in this object
147-
if (containsObjectTypeSpread) {
148-
return {};
149-
}
146+
// Mark if this shape has spread. We will know to consider all props from this shape as having propTypes,
147+
// but still have the ability to detect unused children of this shape.
148+
shapeTypeDefinition.containsSpread = containsObjectTypeSpread;
149+
150150
return shapeTypeDefinition;
151151
},
152152

@@ -669,7 +669,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
669669
JSXSpreadAttribute: function(node) {
670670
const component = components.get(utils.getParentComponent());
671671
components.set(component ? component.node : node, {
672-
ignorePropsValidation: true
672+
ignoreUnusedPropTypesValidation: true
673673
});
674674
},
675675

0 commit comments

Comments
 (0)