Skip to content

Commit 5fc50aa

Browse files
committed
[Fix] Ignore reassignments when matching props declarations with components
Fixes jsx-eslint#2051 Fixes jsx-eslint#1957
1 parent ba80a4c commit 5fc50aa

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/util/Components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function componentRule(rule, context) {
567567
}
568568
if (refId.type === 'MemberExpression') {
569569
componentNode = refId.parent.right;
570-
} else if (refId.parent && refId.parent.type === 'VariableDeclarator') {
570+
} else if (refId.parent && refId.parent.type === 'VariableDeclarator' && refId.parent.init.type !== 'Identifier') {
571571
componentNode = refId.parent.init;
572572
}
573573
break;

tests/lib/rules/prop-types.js

+19
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,25 @@ ruleTester.run('prop-types', rule, {
22772277
'}'
22782278
].join('\n'),
22792279
parser: 'babel-eslint'
2280+
}, {
2281+
code: `
2282+
import React from 'react';
2283+
import PropTypes from 'prop-types';
2284+
import {connect} from 'react-redux';
2285+
2286+
class Foo extends React.Component {
2287+
render() {
2288+
return this.props.children;
2289+
}
2290+
}
2291+
2292+
Foo.propTypes = {
2293+
children: PropTypes.element.isRequired
2294+
};
2295+
2296+
export const Unconnected = Foo;
2297+
export default connect(Foo);
2298+
`
22802299
}
22812300
],
22822301

0 commit comments

Comments
 (0)