Skip to content

Commit

Permalink
Added linting support for private class methods (#11993)
Browse files Browse the repository at this point in the history
* Added linting support for private class methods

* Renamed variable

* Renamed variable
  • Loading branch information
giovannicalo committed Aug 24, 2020
1 parent 76d571e commit 304eea4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 304eea4

Please sign in to comment.