Skip to content

Commit

Permalink
[Fix] prop-types: Fix false positive on computed member expression
Browse files Browse the repository at this point in the history
Fixes #1259
  • Loading branch information
golopot authored and ljharb committed Mar 16, 2019
1 parent 005070d commit d3dc4c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/util/usedPropTypes.js 100644 → 100755
Expand Up @@ -295,7 +295,11 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
name = getPropertyName(node);
if (name) {
allNames = parentNames.concat(name);
if (node.parent.type === 'MemberExpression') {
if (
// Match props.foo.bar, don't match bar[props.foo]
node.parent.type === 'MemberExpression' &&
node.parent.object === node
) {
markPropTypesAsUsed(node.parent, allNames);
}
// Do not mark computed props as used.
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/prop-types.js 100644 → 100755
Expand Up @@ -2303,6 +2303,19 @@ ruleTester.run('prop-types', rule, {
const b = a::fn1();
`,
parser: 'babel-eslint'
},
{
// issue #1259
code: `
const Hello = props => {
const { notInProp } = dict[props.foo];
return <div />
}
Hello.propTypes = {
foo: PropTypes.number,
}
`
}
],

Expand Down

0 comments on commit d3dc4c8

Please sign in to comment.