Skip to content

Commit 6835d8b

Browse files
author
Yannick Croissant
committed
[Fix] no-this-in-sfc: Fix false positive on SFC defined as object property
Fixes #2147
1 parent e1a5889 commit 6835d8b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/rules/no-this-in-sfc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
MemberExpression(node) {
3232
if (node.object.type === 'ThisExpression') {
3333
const component = components.get(utils.getParentStatelessComponent());
34-
if (!component) {
34+
if (!component || component.node && component.node.parent && component.node.parent.type === 'Property') {
3535
return;
3636
}
3737
context.report({

tests/lib/rules/no-this-in-sfc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ ruleTester.run('no-this-in-sfc', rule, {
137137
};
138138
}`,
139139
parser: 'babel-eslint'
140+
}, {
141+
code: `
142+
export const Example = ({ prop }) => {
143+
return {
144+
handleClick: () => {},
145+
renderNode() {
146+
return <div onClick={this.handleClick} />;
147+
},
148+
};
149+
};`,
150+
parser: 'babel-eslint'
140151
}],
141152
invalid: [{
142153
code: `

0 commit comments

Comments
 (0)