-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginstalePRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged periodPRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged periodunable to reproissues that a maintainer was not able to reproduceissues that a maintainer was not able to reproduce
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
{
"rules": {
"@typescript-eslint/unbound-method": "error"
}
}
const collator = new Intl.Collator("en")
const sorted = ["foo", "bar"].sort(collator.compare)
(tsconfig not included as the same issue occurs regardless of config)
Expected Result
No error, as Intl.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. So Intl.Collator
itself is ignored, but Intl.Collator.compare
isn't because it's another level down. Presumably the same issue affects other similar methods like Intl.DateFormat.format
as well -- maybe check the Intl
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 |
Metadata
Metadata
Assignees
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginstalePRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged periodPRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged periodunable to reproissues that a maintainer was not able to reproduceissues that a maintainer was not able to reproduce