From 5fc50aa9238768674cf2a2ca1d9676be629a920a Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Sun, 6 Jan 2019 23:52:58 +0100 Subject: [PATCH] [Fix] Ignore reassignments when matching props declarations with components Fixes #2051 Fixes #1957 --- lib/util/Components.js | 2 +- tests/lib/rules/prop-types.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/util/Components.js b/lib/util/Components.js index 852254e8fe..ef25709557 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -567,7 +567,7 @@ function componentRule(rule, context) { } if (refId.type === 'MemberExpression') { componentNode = refId.parent.right; - } else if (refId.parent && refId.parent.type === 'VariableDeclarator') { + } else if (refId.parent && refId.parent.type === 'VariableDeclarator' && refId.parent.init.type !== 'Identifier') { componentNode = refId.parent.init; } break; diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index b72f043abc..41c2a42677 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2277,6 +2277,25 @@ ruleTester.run('prop-types', rule, { '}' ].join('\n'), parser: 'babel-eslint' + }, { + code: ` + import React from 'react'; + import PropTypes from 'prop-types'; + import {connect} from 'react-redux'; + + class Foo extends React.Component { + render() { + return this.props.children; + } + } + + Foo.propTypes = { + children: PropTypes.element.isRequired + }; + + export const Unconnected = Foo; + export default connect(Foo); + ` } ],