Skip to content

Commit 0ee5e93

Browse files
author
Joachim Seminck
committed
Rewrite reduce to ignorePropsValidation as some()
1 parent 3e9aefe commit 0ee5e93

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -755,28 +755,21 @@ module.exports = {
755755
* @returns {Boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
756756
*/
757757
function declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes) {
758-
return propTypes.types.reduce((ignorePropsValidation, annotation) => {
759-
// If we already decided to skip props validation then we don't have to continue processing anything else
760-
if (ignorePropsValidation) {
761-
return ignorePropsValidation;
758+
return propTypes.types.some(annotation => {
759+
if (annotation.type === 'ObjectTypeAnnotation') {
760+
return declarePropTypesForObjectTypeAnnotation(annotation, declaredPropTypes);
762761
}
763762

764-
if (annotation.type === 'ObjectTypeAnnotation') {
765-
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(annotation, declaredPropTypes);
766-
} else {
767-
const typeNode = typeScope(annotation.id.name);
768-
769-
if (!typeNode) {
770-
ignorePropsValidation = true;
771-
} else if (typeNode.type === 'IntersectionTypeAnnotation') {
772-
ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
773-
} else {
774-
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(typeNode, declaredPropTypes);
775-
}
763+
const typeNode = typeScope(annotation.id.name);
764+
765+
if (!typeNode) {
766+
return true;
767+
} else if (typeNode.type === 'IntersectionTypeAnnotation') {
768+
return declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
776769
}
777770

778-
return ignorePropsValidation;
779-
}, false);
771+
return declarePropTypesForObjectTypeAnnotation(typeNode, declaredPropTypes);
772+
});
780773
}
781774

782775
/**

lib/rules/prop-types.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -745,28 +745,21 @@ module.exports = {
745745
* @returns {Boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
746746
*/
747747
function declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes) {
748-
return propTypes.types.reduce((ignorePropsValidation, annotation) => {
749-
// If we already decided to skip props validation then we don't have to continue processing anything else
750-
if (ignorePropsValidation) {
751-
return ignorePropsValidation;
748+
return propTypes.types.some(annotation => {
749+
if (annotation.type === 'ObjectTypeAnnotation') {
750+
return declarePropTypesForObjectTypeAnnotation(annotation, declaredPropTypes);
752751
}
753752

754-
if (annotation.type === 'ObjectTypeAnnotation') {
755-
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(annotation, declaredPropTypes);
756-
} else {
757-
const typeNode = typeScope(annotation.id.name);
753+
const typeNode = typeScope(annotation.id.name);
758754

759-
if (!typeNode) {
760-
ignorePropsValidation = true;
761-
} else if (typeNode.type === 'IntersectionTypeAnnotation') {
762-
ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
763-
} else {
764-
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(typeNode, declaredPropTypes);
765-
}
755+
if (!typeNode) {
756+
return true;
757+
} else if (typeNode.type === 'IntersectionTypeAnnotation') {
758+
return declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
766759
}
767760

768-
return ignorePropsValidation;
769-
}, false);
761+
return declarePropTypesForObjectTypeAnnotation(typeNode, declaredPropTypes);
762+
});
770763
}
771764

772765
/**

0 commit comments

Comments
 (0)