diff --git a/lib/util/usedPropTypes.js b/lib/util/usedPropTypes.js index 9270d8bcf0..0b412511fc 100755 --- a/lib/util/usedPropTypes.js +++ b/lib/util/usedPropTypes.js @@ -356,21 +356,19 @@ module.exports = function usedPropTypesInstructions(context, components, utils) } const propName = ast.getKeyValue(context, properties[k]); - if (propName) { - propVariables.set(propName, parentNames.concat(propName)); - usedPropTypes.push({ - allNames: parentNames.concat([propName]), - name: propName, - node: properties[k] - }); - } - if ( propName && properties[k].type === 'Property' && properties[k].value.type === 'ObjectPattern' ) { markPropTypesAsUsed(properties[k].value, parentNames.concat([propName])); + } else if (propName) { + propVariables.set(propName, parentNames.concat(propName)); + usedPropTypes.push({ + allNames: parentNames.concat([propName]), + name: propName, + node: properties[k] + }); } } break; diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index abba1caf2a..bcdee30c03 100755 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2498,7 +2498,6 @@ ruleTester.run('prop-types', rule, { } `, errors: [ - {message: "'foo' is missing in props validation"}, {message: "'foo.bar' is missing in props validation"} ] }, { @@ -2526,7 +2525,6 @@ ruleTester.run('prop-types', rule, { } `, errors: [ - {message: "'foo' is missing in props validation"}, {message: "'foo.bar' is missing in props validation"} ] }, @@ -4808,6 +4806,27 @@ ruleTester.run('prop-types', rule, { errors: [{ message: '\'text\' is missing in props validation' }] + }, + { + code: ` + function Foo({ + foo: { + bar: foo, + baz + }, + }) { + return

{foo.reduce(() => 5)}

; + } + + Foo.propTypes = { + foo: PropTypes.shape({ + bar: PropTypes.arrayOf(PropTypes.string).isRequired, + }).isRequired, + }; + `, + errors: [{ + message: '\'foo.baz\' is missing in props validation' + }] } ] });