Skip to content

[unbound-method] False positive on Intl.Collator.compare #4383

@kestrelnova

Description

@kestrelnova
  • 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

No one assigned

    Labels

    package: 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 periodunable to reproissues that a maintainer was not able to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy