-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(eslint-plugin): [unbound-method] report property signatures with function types #11682
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -463,7 +463,11 @@ class Foo { | |||||||||||||||||||||||||||
| type foo = new ({ unbound }: Foo) => void; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| 'const { unbound } = { unbound: () => {} };', | ||||||||||||||||||||||||||||
| 'function foo({ unbound }: { unbound: () => void } = { unbound: () => {} }) {}', | ||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||
| function foo( | ||||||||||||||||||||||||||||
| { unbound }: { unbound: (this: void) => void } = { unbound: () => {} }, | ||||||||||||||||||||||||||||
| ) {} | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| // https://github.com/typescript-eslint/typescript-eslint/issues/1866 | ||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||
| class BaseClass { | ||||||||||||||||||||||||||||
|
|
@@ -480,6 +484,30 @@ class OtherClass extends BaseClass { | |||||||||||||||||||||||||||
| const oc = new OtherClass(); | ||||||||||||||||||||||||||||
| oc.superLogThis(); | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||
| interface Foo { | ||||||||||||||||||||||||||||
| bound: (this: void) => number; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| foo.bound; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||
| interface Foo { | ||||||||||||||||||||||||||||
| bound: (this: void) => number; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| const { bound } = foo; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||
| type Foo = { | ||||||||||||||||||||||||||||
| bound: (this: void) => number; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| const { bound } = foo; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| invalid: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
|
|
@@ -965,7 +993,7 @@ function foo({ unbound }: { unbound: () => string } | Foo) {} | |||||||||||||||||||||||||||
| errors: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| line: 5, | ||||||||||||||||||||||||||||
| messageId: 'unbound', | ||||||||||||||||||||||||||||
| messageId: 'unboundWithoutThisAnnotation', | ||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is interesting, it seems the rule iterates on union types and reports the first violation: typescript-eslint/packages/eslint-plugin/src/rules/unbound-method.ts Lines 263 to 275 in 7f5fed7
In this case, the union starts with This PR made it so
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhat related: #11683. |
||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
|
|
@@ -1252,5 +1280,69 @@ const f = objectLiteral.f; | |||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| code: ` | ||||||||||||||||||||||||||||
| interface Foo { | ||||||||||||||||||||||||||||
| bound: () => number; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| foo.bound; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| errors: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| line: 7, | ||||||||||||||||||||||||||||
| messageId: 'unboundWithoutThisAnnotation', | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| code: ` | ||||||||||||||||||||||||||||
| interface Foo { | ||||||||||||||||||||||||||||
| bound: () => number; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| const { bound } = foo; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| errors: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| line: 7, | ||||||||||||||||||||||||||||
| messageId: 'unboundWithoutThisAnnotation', | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| code: ` | ||||||||||||||||||||||||||||
| interface Foo { | ||||||||||||||||||||||||||||
| bound: (this: Foo) => number; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| foo.bound; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| errors: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| line: 7, | ||||||||||||||||||||||||||||
| messageId: 'unbound', | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| code: ` | ||||||||||||||||||||||||||||
| type Foo = { | ||||||||||||||||||||||||||||
| bound: () => number; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| declare const foo: Foo; | ||||||||||||||||||||||||||||
| foo.bound; | ||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||
| errors: [ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| line: 7, | ||||||||||||||||||||||||||||
| messageId: 'unboundWithoutThisAnnotation', | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my understanding, this previously valid test is in fact invalid without a
this: voidparameter type.