Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): specify which method is unbound and added test case #6281

Merged
merged 2 commits into from Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/unbound-method.ts
Expand Up @@ -241,7 +241,7 @@ export default util.createRule<Options, MessageIds>({
}

checkMethodAndReport(
node,
property.key,
initTypes.getProperty(property.key.name),
);
}
Expand Down
54 changes: 54 additions & 0 deletions packages/eslint-plugin/tests/rules/unbound-method.test.ts
Expand Up @@ -590,5 +590,59 @@ class OtherClass extends BaseClass {
},
],
},
{
code: `
const values = {
a() {},
b: () => {},
};

const { a, b } = values;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more test cases come to mind:

  • const { a: c } = values;
  • const { b, a } = values;

`,
errors: [
{
line: 7,
column: 9,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the endColumn here too? That way we know it's on the a, not a, b or some other odd range.

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',
},
],
},
],
});