Skip to content

Commit

Permalink
Do not mark inline functions in JSX as components (fixes #546)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Apr 17, 2016
1 parent 68ed8af commit c1c38eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ function componentRule(rule, context) {

FunctionExpression: function(node) {
node = utils.getParentComponent();
if (!node) {
if (
!node ||
(node.parent && node.parent.type === 'JSXExpressionContainer')
) {
return;
}
components.add(node, 1);
Expand All @@ -407,7 +410,10 @@ function componentRule(rule, context) {

ArrowFunctionExpression: function(node) {
node = utils.getParentComponent();
if (!node) {
if (
!node ||
(node.parent && node.parent.type === 'JSXExpressionContainer')
) {
return;
}
if (node.expression && utils.isReturningJSX(node)) {
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,20 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'function Greetings() {',
' return <div>{({name}) => <Hello name={name} />}</div>',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'function Greetings() {',
' return <div>{function({name}) { return <Hello name={name} />; }}</div>',
'}'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit c1c38eb

Please sign in to comment.