Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
{"rules": {"@typescript-eslint/unbound-method":"error" }}
constcollator=newIntl.Collator("en")constsorted=["foo","bar"].sort(collator.compare)
(tsconfig not included as the same issue occurs regardless of config)
Expected Result
No error, asIntl.Collator.compare
is a native bound method intended to be used this way.
Actual Result
2:36 error Avoid referencing unbound methods which may cause unintentional scoping of `this`.If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead @typescript-eslint/unbound-method
Additional Info
The rule's source code does account for builtins, but it looks like only top-level bound methods are put on the list to ignore when checking. SoIntl.Collator
itself is ignored, butIntl.Collator.compare
isn't because it's another level down. Presumably the same issue affects other similar methods likeIntl.DateFormat.format
as well -- maybe check theIntl
constructors individually when generating the ignore list?
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin | 5.8.1 |
@typescript-eslint/parser | 5.8.1 |
TypeScript | 4.5.4 |
ESLint | 8.6.0 |
node | 17.3.0 |