Skip to content

Bug: [@typescript-eslint/member-ordering] no error raised when accessors not sorted by alphabetical order #9765

@OlivierZal

Description

@OlivierZal

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.5.4&fileType=.ts&code=KYDwDg9gTgLgBAE2AMwIYFcA28DGnUDOBcA3gFBxxjoBGmAljnKjjsEdMwFxwExT0AdgHM4AXjgByVJLIUqtBkxZsOUODh58BI8VJyz5AeiNwAygAsIWBHCip6BYM0FxgUKJwJC2cAAY0fnCOcDQo0M5%2BOEFCcDAWzqiYYBaoYTCMSXDQSFAANKHo8AgQ7HCCEDDy1HSMzKzsBJw0WvxCohKSNIaURgBUcACSyHAAntbBggBu7vABQaiCtn7AABQAlH4F8c7IEJiYEADu7W4enCcHoc72jsAIXPKUkgCywAC2YeqCWJi8VjZrohgHhUFB7tc9uDmFcakpJnxFr53sB4hBbEhkEJ6BkIIICAA6OAARgAbFwAMxwAC0JPJFIALLJKJRVkdUvAUYtiPFUHNAsFiOCcBBhIJ6AAvCGEZjlPHUoSIwTI1FWBAFJpxBJ2LCJMBgBhlI7AA55J6FeA4mGarn4rV8rU3XVaoQAax5HP8ApCglQKOWPwOfnW8j6Rmqijqa3WPCmEHotnILLsqPQUEE8gAvnJeqYAEoOJwuM6edTeZWRBAxYhhKGRYAxVw7GEpNKozJ-HLuDUQR06zB6g30I0mzAR2pMBAbWPxxPm8EwNMZyjZzNAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AW0XYCNFpaA9tAAmfZgHN0YANrhsOPtCGQANHPlZ52SKIBmAQwT4pmrds48%2BAFRIopss2cj6yZFMmVrHWyJ3wALAWFIdUcAXS9vKCFRaClIJn18WGh9eBDvAF9QiGz5MLlszKA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkAJutKgIabMHEVh6YCu6AGnA16jFmw5EAss0Rce-ITSipkAIy4BtYcvoJIAqOhJF0ADzyQdYALpKR8WHV4YukIk-SmLB6%2B9gAkkiq0Mh42ABuWJjIDPJ8gn6wvHgAIsiYbnTIJJb2tJiwsGkZbiSY0L66JADWyIgAMuoAwgAWjDXxin4kyRXoMnKUConVPMjQlsMJ%2BVB4rADm6FNGJABMAAxra1YQAL4ge0A&tokens=false

Repro Code

export default class {
  public accessor a: string = 'a'

  public accessor c: string = 'c'

  // Should raise an error since `b` is before `c` in the alphabetical order, but does not
  public accessor b: string = 'b'

  /* If you invert `b` and `e()`, the following error will be raised:
    'Member null should be declared before all public instance method definitions. 16:3 - 16:34'
    (what means that `b` is recognized as a non-instance method, so the rule applies well,
    but it also means that the rule thinks that `b` is named `null`)
  */
  public e(): void {
    return
  }

  // Raise an error since `d` is before `e` in the alphabetical order, so the rule applies well
  public d(): void {
    return
  }
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/member-ordering": [
      "error",
      {
        "default": {
          "memberTypes": [
            "accessor",
            "method"
          ],
          "order": "natural"
        }
      }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "lib": [
      "dom", "esnext"
    ],
    "module": "nodenext",
    "noImplicitOverride": true,
    "outDir": "dist",
    "rootDir": "src",
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2022"
  }
}

Expected Result

I expected the 7th line should report the error:

Member b should be declared before member c. 7:3 - 7:34

Actual Result

There was no error on 7th line.

Additional Info

If you invert b and e(), the following error will be raised:

Member null should be declared before all method definitions. 16:3 - 16:34

what means that b is recognized as a non-method, so the rule applies well, but it also means that the rule thinks that b is named null.

If you invert accessor and method in the eslint config:

{
  "rules": {
    "@typescript-eslint/member-ordering": [
      "error",
      {
        "default": {
          "memberTypes": [
            "method",
            "accessor"
          ],
          "order": "natural"
        }
      }
    ]
  }
}

a, b and c are well recognized as accessors according to the new error messages:

Member e should be declared before all accessor definitions. 14:3 - 16:4
Member d should be declared before all accessor definitions. 19:3 - 21:4

My assumption is that each accessor is treated as if it were named null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    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