Skip to content

Commit

Permalink
function-component-definition: ignore properties
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwullems committed Aug 26, 2020
1 parent 2588c4d commit a5b7dcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/function-component-definition.js
Expand Up @@ -156,6 +156,9 @@ module.exports = {

function validate(node, functionType) {
if (!components.get(node)) return;
// Fix for https://github.com/yannickcr/eslint-plugin-react/issues/2765
if (node.parent && node.parent.type === 'Property') return;

if (hasName(node) && namedConfig !== functionType) {
report(node, {
message: ERROR_MESSAGES[namedConfig],
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/function-component-definition.js
Expand Up @@ -166,6 +166,16 @@ ruleTester.run('function-component-definition', rule, {
code: 'function Hello(props): ReactNode { return <p/> }',
options: [{namedComponents: 'function-declaration'}],
parser: parsers.TYPESCRIPT_ESLINT
}, {
// https://github.com/yannickcr/eslint-plugin-react/issues/2765
code: [
'const obj = {',
' serialize(el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'arrow-function'}]
}],

invalid: [{
Expand Down

0 comments on commit a5b7dcf

Please sign in to comment.