From fbec99ea3e39316791685652c66e522d698f52d8 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sat, 10 Aug 2019 18:12:06 +0200 Subject: [PATCH] Update: fix class-methods-use-this false negatives with exceptMethods (#12077) --- lib/rules/class-methods-use-this.js | 3 ++- tests/lib/rules/class-methods-use-this.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rules/class-methods-use-this.js b/lib/rules/class-methods-use-this.js index 0eb1da87f4c..c15f32e66dc 100644 --- a/lib/rules/class-methods-use-this.js +++ b/lib/rules/class-methods-use-this.js @@ -70,7 +70,8 @@ module.exports = { * @private */ function isIncludedInstanceMethod(node) { - return isInstanceMethod(node) && !exceptMethods.has(node.key.name); + return isInstanceMethod(node) && + (node.computed || !exceptMethods.has(node.key.name)); } /** diff --git a/tests/lib/rules/class-methods-use-this.js b/tests/lib/rules/class-methods-use-this.js index 8521242457f..89af434fd59 100644 --- a/tests/lib/rules/class-methods-use-this.js +++ b/tests/lib/rules/class-methods-use-this.js @@ -97,6 +97,14 @@ ruleTester.run("class-methods-use-this", rule, { errors: [ { type: "FunctionExpression", line: 1, column: 34, messageId: "missingThis", data: { name: "hasOwnProperty" } } ] + }, + { + code: "class A { [foo]() {} }", + options: [{ exceptMethods: ["foo"] }], + parserOptions: { ecmaVersion: 6 }, + errors: [ + { type: "FunctionExpression", line: 1, column: 16, messageId: "missingThis", data: { name: "foo" } } + ] } ] });