Skip to content

Commit e71feb5

Browse files
committed
[Fix] forbid-prop-types: fix crash with propWrapper check on MemberExpressions
Fixes #2104.
1 parent 11a66c0 commit e71feb5

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

lib/rules/forbid-prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module.exports = {
125125
break;
126126
case 'CallExpression':
127127
const innerNode = node.arguments && node.arguments[0];
128-
if (propWrapperUtil.isPropWrapperFunction(context, node.callee.name) && innerNode) {
128+
if (propWrapperUtil.isPropWrapperFunction(context, context.getSource(node.callee)) && innerNode) {
129129
checkNode(innerNode);
130130
}
131131
break;

tests/lib/rules/forbid-prop-types.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ ruleTester.run('forbid-prop-types', rule, {
179179
}, {
180180
// Proptypes declared with a spread property
181181
code: [
182-
'class Test extends react.component {',
182+
'class Test extends React.component {',
183183
' static propTypes = {',
184184
' intl: React.propTypes.number,',
185185
' ...propTypes',
@@ -190,7 +190,7 @@ ruleTester.run('forbid-prop-types', rule, {
190190
}, {
191191
// Proptypes declared with a spread property
192192
code: [
193-
'class Test extends react.component {',
193+
'class Test extends React.component {',
194194
' static get propTypes() {',
195195
' return {',
196196
' intl: React.propTypes.number,',
@@ -351,7 +351,7 @@ ruleTester.run('forbid-prop-types', rule, {
351351
}, {
352352
// Proptypes declared with a spread property
353353
code: [
354-
'class Test extends react.component {',
354+
'class Test extends React.component {',
355355
' static childContextTypes = {',
356356
' intl: React.childContextTypes.number,',
357357
' ...childContextTypes',
@@ -363,7 +363,7 @@ ruleTester.run('forbid-prop-types', rule, {
363363
}, {
364364
// Proptypes declared with a spread property
365365
code: [
366-
'class Test extends react.component {',
366+
'class Test extends React.component {',
367367
' static get childContextTypes() {',
368368
' return {',
369369
' intl: React.childContextTypes.number,',
@@ -525,7 +525,7 @@ ruleTester.run('forbid-prop-types', rule, {
525525
}, {
526526
// Proptypes declared with a spread property
527527
code: [
528-
'class Test extends react.component {',
528+
'class Test extends React.component {',
529529
' static childContextTypes = {',
530530
' intl: React.childContextTypes.number,',
531531
' ...childContextTypes',
@@ -537,7 +537,7 @@ ruleTester.run('forbid-prop-types', rule, {
537537
}, {
538538
// Proptypes declared with a spread property
539539
code: [
540-
'class Test extends react.component {',
540+
'class Test extends React.component {',
541541
' static get childContextTypes() {',
542542
' return {',
543543
' intl: React.childContextTypes.number,',
@@ -547,6 +547,28 @@ ruleTester.run('forbid-prop-types', rule, {
547547
'}'
548548
].join('\n'),
549549
options: [{checkChildContextTypes: true}]
550+
}, {
551+
code: [
552+
'class TestComponent extends React.Component {',
553+
' static defaultProps = function () {',
554+
' const date = new Date();',
555+
' return {',
556+
' date',
557+
' };',
558+
' }();',
559+
'}'
560+
].join('\n'),
561+
parser: 'babel-eslint'
562+
}, {
563+
code: [
564+
'class HeroTeaserList extends React.Component {',
565+
' render() { return null; }',
566+
'}',
567+
'HeroTeaserList.propTypes = Object.assign({',
568+
' heroIndex: PropTypes.number,',
569+
' preview: PropTypes.bool,',
570+
'}, componentApi, teaserListProps);'
571+
].join('\n')
550572
}],
551573

552574
invalid: [{

0 commit comments

Comments
 (0)