Skip to content

Commit

Permalink
[Fix] no-this-in-sfc: Fix false positive on SFC defined as object p…
Browse files Browse the repository at this point in the history
…roperty

Fixes #2147
  • Loading branch information
Yannick Croissant committed Mar 5, 2019
1 parent e1a5889 commit 6835d8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-this-in-sfc.js
Expand Up @@ -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({
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-this-in-sfc.js
Expand Up @@ -137,6 +137,17 @@ ruleTester.run('no-this-in-sfc', rule, {
};
}`,
parser: 'babel-eslint'
}, {
code: `
export const Example = ({ prop }) => {
return {
handleClick: () => {},
renderNode() {
return <div onClick={this.handleClick} />;
},
};
};`,
parser: 'babel-eslint'
}],
invalid: [{
code: `
Expand Down

0 comments on commit 6835d8b

Please sign in to comment.