Skip to content

Commit 655eb01

Browse files
authored
Merge pull request jsx-eslint#2320 from golopot/issue-2319
[Fix] `prop-types`: fix crash on multiple destructuring
2 parents dfaa92f + 9639d82 commit 655eb01

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/util/usedPropTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
489489

490490
// let {firstname} = thing, where thing is defined by const thing = this.props.**.*
491491
if (propVariables.get(node.init.name)) {
492-
markPropTypesAsUsed(node, propVariables.get(node.init.name));
492+
markPropTypesAsUsed(node.id, propVariables.get(node.init.name));
493493
}
494494
},
495495

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,22 @@ ruleTester.run('no-unused-prop-types', rule, {
492492
`,
493493
options: [{skipShapeProps: false}],
494494
parser: parsers.BABEL_ESLINT
495+
}, {
496+
code: `
497+
function Foo({ a }) {
498+
const { b } = a
499+
return <>{ b.c }</>
500+
}
501+
Foo.propTypes = {
502+
a: PropTypes.shape({
503+
b: PropType.shape({
504+
c: PropTypes.string,
505+
}),
506+
})
507+
}
508+
`,
509+
options: [{skipShapeProps: false}],
510+
parser: parsers.BABEL_ESLINT
495511
}, {
496512
// Destructured assignment with Shape propTypes with skipShapeProps off issue #816
497513
code: `

tests/lib/rules/prop-types.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,25 @@ ruleTester.run('prop-types', rule, {
24722472
{message: "'a.nope' is missing in props validation"}
24732473
]
24742474
},
2475+
{
2476+
code: `
2477+
function Foo({ a }) {
2478+
const { b } = a
2479+
return <p>{ b.nope }</p>
2480+
}
2481+
2482+
Foo.propTypes = {
2483+
a: PropTypes.shape({
2484+
b: PropType.shape({
2485+
_: PropType.string,
2486+
}),
2487+
})
2488+
}
2489+
`,
2490+
errors: [
2491+
{message: "'a.b.nope' is missing in props validation"}
2492+
]
2493+
},
24752494
{
24762495
code: `
24772496
function Foo(props) {

0 commit comments

Comments
 (0)