Skip to content

Commit

Permalink
Merge pull request #2320 from golopot/issue-2319
Browse files Browse the repository at this point in the history
[Fix] `prop-types`: fix crash on multiple destructuring
  • Loading branch information
ljharb committed Jun 24, 2019
2 parents dfaa92f + 9639d82 commit 655eb01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/usedPropTypes.js
Expand Up @@ -489,7 +489,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)

// let {firstname} = thing, where thing is defined by const thing = this.props.**.*
if (propVariables.get(node.init.name)) {
markPropTypesAsUsed(node, propVariables.get(node.init.name));
markPropTypesAsUsed(node.id, propVariables.get(node.init.name));
}
},

Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -492,6 +492,22 @@ ruleTester.run('no-unused-prop-types', rule, {
`,
options: [{skipShapeProps: false}],
parser: parsers.BABEL_ESLINT
}, {
code: `
function Foo({ a }) {
const { b } = a
return <>{ b.c }</>
}
Foo.propTypes = {
a: PropTypes.shape({
b: PropType.shape({
c: PropTypes.string,
}),
})
}
`,
options: [{skipShapeProps: false}],
parser: parsers.BABEL_ESLINT
}, {
// Destructured assignment with Shape propTypes with skipShapeProps off issue #816
code: `
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -2472,6 +2472,25 @@ ruleTester.run('prop-types', rule, {
{message: "'a.nope' is missing in props validation"}
]
},
{
code: `
function Foo({ a }) {
const { b } = a
return <p>{ b.nope }</p>
}
Foo.propTypes = {
a: PropTypes.shape({
b: PropType.shape({
_: PropType.string,
}),
})
}
`,
errors: [
{message: "'a.b.nope' is missing in props validation"}
]
},
{
code: `
function Foo(props) {
Expand Down

0 comments on commit 655eb01

Please sign in to comment.