From cf3ffdd49aceb734ce18dc44ed6a11f7701f178e Mon Sep 17 00:00:00 2001 From: Cparros <65684072+cparros@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:18:39 -0700 Subject: [PATCH] feat(eslint-plugin): specify which method is unbound and added test case (#6281) * Unbound-method test case added and specified error location * test case update --- .../eslint-plugin/src/rules/unbound-method.ts | 2 +- .../tests/rules/unbound-method.test.ts | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index c95a7fd35e1..6741f4df09f 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -241,7 +241,7 @@ export default util.createRule({ } checkMethodAndReport( - node, + property.key, initTypes.getProperty(property.key.name), ); } diff --git a/packages/eslint-plugin/tests/rules/unbound-method.test.ts b/packages/eslint-plugin/tests/rules/unbound-method.test.ts index 2105ef41e59..49b06a4ac50 100644 --- a/packages/eslint-plugin/tests/rules/unbound-method.test.ts +++ b/packages/eslint-plugin/tests/rules/unbound-method.test.ts @@ -590,5 +590,59 @@ class OtherClass extends BaseClass { }, ], }, + { + code: ` +const values = { + a() {}, + b: () => {}, +}; + +const { a, b } = values; + `, + errors: [ + { + line: 7, + column: 9, + endColumn: 10, + messageId: 'unboundWithoutThisAnnotation', + }, + ], + }, + { + code: ` +const values = { + a() {}, + b: () => {}, +}; + +const { a: c } = values; + `, + errors: [ + { + line: 7, + column: 9, + endColumn: 10, + messageId: 'unboundWithoutThisAnnotation', + }, + ], + }, + { + code: ` +const values = { + a() {}, + b: () => {}, +}; + +const { b, a } = values; + `, + errors: [ + { + line: 7, + column: 12, + endColumn: 13, + messageId: 'unboundWithoutThisAnnotation', + }, + ], + }, ], });