babel/eslint/babel-eslint-plugin/rules/no-invalid-this.js
fergald f3e2752df3 Support private properties in no-invalid-this (babel/eslint-plugin-babel#183)
* add failing test

* support ClassPrivateProperty
2019-08-24 17:12:15 +09:00

26 lines
645 B
JavaScript

"use strict";
const ruleComposer = require('eslint-rule-composer');
const eslint = require('eslint');
const noInvalidThisRule = new eslint.Linter().getRules().get('no-invalid-this');
module.exports = ruleComposer.filterReports(
noInvalidThisRule,
(problem, metadata) => {
let inClassProperty = false;
let node = problem.node;
while (node) {
if (node.type === "ClassProperty" ||
node.type === "ClassPrivateProperty") {
inClassProperty = true;
return;
}
node = node.parent;
}
return !inClassProperty;
}
);