Skip to content

Commit c1c38eb

Browse files
committed
Do not mark inline functions in JSX as components (fixes #546)
1 parent 68ed8af commit c1c38eb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/util/Components.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ function componentRule(rule, context) {
391391

392392
FunctionExpression: function(node) {
393393
node = utils.getParentComponent();
394-
if (!node) {
394+
if (
395+
!node ||
396+
(node.parent && node.parent.type === 'JSXExpressionContainer')
397+
) {
395398
return;
396399
}
397400
components.add(node, 1);
@@ -407,7 +410,10 @@ function componentRule(rule, context) {
407410

408411
ArrowFunctionExpression: function(node) {
409412
node = utils.getParentComponent();
410-
if (!node) {
413+
if (
414+
!node ||
415+
(node.parent && node.parent.type === 'JSXExpressionContainer')
416+
) {
411417
return;
412418
}
413419
if (node.expression && utils.isReturningJSX(node)) {

tests/lib/rules/prop-types.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,20 @@ ruleTester.run('prop-types', rule, {
11921192
'}'
11931193
].join('\n'),
11941194
parser: 'babel-eslint'
1195+
}, {
1196+
code: [
1197+
'function Greetings() {',
1198+
' return <div>{({name}) => <Hello name={name} />}</div>',
1199+
'}'
1200+
].join('\n'),
1201+
parser: 'babel-eslint'
1202+
}, {
1203+
code: [
1204+
'function Greetings() {',
1205+
' return <div>{function({name}) { return <Hello name={name} />; }}</div>',
1206+
'}'
1207+
].join('\n'),
1208+
parser: 'babel-eslint'
11951209
}
11961210
],
11971211

0 commit comments

Comments
 (0)