Skip to content

Commit

Permalink
[Fix] Ignore reassignments when matching props declarations with comp…
Browse files Browse the repository at this point in the history
…onents

Fixes #2051
Fixes #1957
  • Loading branch information
yannickcr committed Jan 6, 2019
1 parent ba80a4c commit 5fc50aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/Components.js
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -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);
`
}
],

Expand Down

0 comments on commit 5fc50aa

Please sign in to comment.