Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not filter report from functions within class elements #13106

Merged
merged 1 commit into from Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion eslint/babel-eslint-plugin/src/rules/no-invalid-this.js
Expand Up @@ -17,7 +17,13 @@ export default ruleComposer.filterReports(noInvalidThisRule, problem => {
node.key.type === "PrivateIdentifier")
) {
inClassMember = true;
return;
break;
} else if (
node.type === "FunctionDeclaration" ||
node.type === "FunctionExpression"
) {
inClassMember = false;
break;
}

node = node.parent;
Expand Down
48 changes: 48 additions & 0 deletions eslint/babel-eslint-plugin/test/rules/no-invalid-this.js
Expand Up @@ -93,6 +93,30 @@ const patterns = [
invalid: [],
},

{
code: "class A {a = () => { function b() { return this.b;} };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

{
code: "class A {a = () => { (function b() { return this.b;}); };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

// Class Private methods
{
code: "class A {#a = this.b;};",
Expand All @@ -108,6 +132,30 @@ const patterns = [
invalid: [],
},

{
code: "class A {#a = () => { function b() { return this.b;} };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

{
code: "class A {#a = () => { (function b() { return this.b;}); };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

{
code: "class A {#a() {return this.b;};};",
parserOptions: { ecmaVersion: 6 },
Expand Down