Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] prop-types: fix crash on multiple destructuring #2320

Merged
merged 1 commit into from Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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