From c1c38ebaf5180476123ab11cab2767bcc8b4c926 Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Sun, 17 Apr 2016 18:24:45 +0000 Subject: [PATCH] Do not mark inline functions in JSX as components (fixes #546) --- lib/util/Components.js | 10 ++++++++-- tests/lib/rules/prop-types.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/util/Components.js b/lib/util/Components.js index 5e9235e28d..039ab5549a 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -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); @@ -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)) { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 24f1b0df16..86e2f0358e 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -1192,6 +1192,20 @@ ruleTester.run('prop-types', rule, { '}' ].join('\n'), parser: 'babel-eslint' + }, { + code: [ + 'function Greetings() {', + ' return
{({name}) => }
', + '}' + ].join('\n'), + parser: 'babel-eslint' + }, { + code: [ + 'function Greetings() {', + ' return
{function({name}) { return ; }}
', + '}' + ].join('\n'), + parser: 'babel-eslint' } ],