diff --git a/lib/rules/no-this-in-sfc.js b/lib/rules/no-this-in-sfc.js index 8d715e7bae..5d3749d71f 100644 --- a/lib/rules/no-this-in-sfc.js +++ b/lib/rules/no-this-in-sfc.js @@ -31,7 +31,7 @@ module.exports = { MemberExpression(node) { if (node.object.type === 'ThisExpression') { const component = components.get(utils.getParentStatelessComponent()); - if (!component) { + if (!component || component.node && component.node.parent && component.node.parent.type === 'Property') { return; } context.report({ diff --git a/tests/lib/rules/no-this-in-sfc.js b/tests/lib/rules/no-this-in-sfc.js index b5d87f0267..d161fa1336 100644 --- a/tests/lib/rules/no-this-in-sfc.js +++ b/tests/lib/rules/no-this-in-sfc.js @@ -137,6 +137,17 @@ ruleTester.run('no-this-in-sfc', rule, { }; }`, parser: 'babel-eslint' + }, { + code: ` + export const Example = ({ prop }) => { + return { + handleClick: () => {}, + renderNode() { + return
; + }, + }; + };`, + parser: 'babel-eslint' }], invalid: [{ code: `