Added linting support for private class methods (#11993)

* Added linting support for private class methods

* Renamed variable

* Renamed variable
This commit is contained in:
Giovanni Calò 2020-08-24 19:57:17 +01:00 committed by GitHub
parent 76d571e285
commit 304eea4133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -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;
});

View File

@ -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();