Skip to content

Commit

Permalink
Update: fix class-methods-use-this false negatives with exceptMethods (
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and platinumazure committed Aug 10, 2019
1 parent fb08b7c commit fbec99e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/class-methods-use-this.js
Expand Up @@ -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));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/class-methods-use-this.js
Expand Up @@ -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" } }
]
}
]
});

0 comments on commit fbec99e

Please sign in to comment.