Skip to content

Commit

Permalink
[Fix] forbid-prop-types: fix crash with propWrapper check on Member…
Browse files Browse the repository at this point in the history
…Expressions

Fixes #2104.
  • Loading branch information
ljharb committed Jan 2, 2019
1 parent 11a66c0 commit e71feb5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = {
break;
case 'CallExpression':
const innerNode = node.arguments && node.arguments[0];
if (propWrapperUtil.isPropWrapperFunction(context, node.callee.name) && innerNode) {
if (propWrapperUtil.isPropWrapperFunction(context, context.getSource(node.callee)) && innerNode) {
checkNode(innerNode);
}
break;
Expand Down
34 changes: 28 additions & 6 deletions tests/lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ruleTester.run('forbid-prop-types', rule, {
}, {
// Proptypes declared with a spread property
code: [
'class Test extends react.component {',
'class Test extends React.component {',
' static propTypes = {',
' intl: React.propTypes.number,',
' ...propTypes',
Expand All @@ -190,7 +190,7 @@ ruleTester.run('forbid-prop-types', rule, {
}, {
// Proptypes declared with a spread property
code: [
'class Test extends react.component {',
'class Test extends React.component {',
' static get propTypes() {',
' return {',
' intl: React.propTypes.number,',
Expand Down Expand Up @@ -351,7 +351,7 @@ ruleTester.run('forbid-prop-types', rule, {
}, {
// Proptypes declared with a spread property
code: [
'class Test extends react.component {',
'class Test extends React.component {',
' static childContextTypes = {',
' intl: React.childContextTypes.number,',
' ...childContextTypes',
Expand All @@ -363,7 +363,7 @@ ruleTester.run('forbid-prop-types', rule, {
}, {
// Proptypes declared with a spread property
code: [
'class Test extends react.component {',
'class Test extends React.component {',
' static get childContextTypes() {',
' return {',
' intl: React.childContextTypes.number,',
Expand Down Expand Up @@ -525,7 +525,7 @@ ruleTester.run('forbid-prop-types', rule, {
}, {
// Proptypes declared with a spread property
code: [
'class Test extends react.component {',
'class Test extends React.component {',
' static childContextTypes = {',
' intl: React.childContextTypes.number,',
' ...childContextTypes',
Expand All @@ -537,7 +537,7 @@ ruleTester.run('forbid-prop-types', rule, {
}, {
// Proptypes declared with a spread property
code: [
'class Test extends react.component {',
'class Test extends React.component {',
' static get childContextTypes() {',
' return {',
' intl: React.childContextTypes.number,',
Expand All @@ -547,6 +547,28 @@ ruleTester.run('forbid-prop-types', rule, {
'}'
].join('\n'),
options: [{checkChildContextTypes: true}]
}, {
code: [
'class TestComponent extends React.Component {',
' static defaultProps = function () {',
' const date = new Date();',
' return {',
' date',
' };',
' }();',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'class HeroTeaserList extends React.Component {',
' render() { return null; }',
'}',
'HeroTeaserList.propTypes = Object.assign({',
' heroIndex: PropTypes.number,',
' preview: PropTypes.bool,',
'}, componentApi, teaserListProps);'
].join('\n')
}],

invalid: [{
Expand Down

0 comments on commit e71feb5

Please sign in to comment.