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

Added linting support for private class methods #11993

Merged
merged 3 commits into from Aug 24, 2020
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
12 changes: 8 additions & 4 deletions eslint/babel-eslint-plugin/src/rules/no-invalid-this.js
Expand Up @@ -4,17 +4,21 @@ import eslint from "eslint";
const noInvalidThisRule = new eslint.Linter().getRules().get("no-invalid-this");

export default ruleComposer.filterReports(noInvalidThisRule, problem => {
let inClassProperty = false;
let inClassMember = false;
let node = problem.node;

while (node) {
if (node.type === "ClassProperty" || node.type === "ClassPrivateProperty") {
inClassProperty = true;
if (
node.type === "ClassPrivateMethod" ||
node.type === "ClassPrivateProperty" ||
node.type === "ClassProperty"
) {
inClassMember = true;
return;
}

node = node.parent;
}

return !inClassProperty;
return !inClassMember;
});
7 changes: 7 additions & 0 deletions eslint/babel-eslint-plugin/test/rules/no-invalid-this.js
Expand Up @@ -107,6 +107,13 @@ const patterns = [
valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
invalid: [],
},

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

const ruleTester = new RuleTester();
Expand Down