Search code examples
jsontypescripteslintrules

@typescript-eslint/member-ordering not working


I'm trying to have a strict ordering in typescript classes, forcing a precise order for groups and especially I'd like to force alphabetic order.

I'm following this doc to achieve what I need: https://typescript-eslint-armano.netlify.app/rules/member-ordering/#sorting-alphabetically-within-member-groups

This is the member-ordering config extracted by my .eslintrc config

"@typescript-eslint/member-ordering": [
      "error",
      {
          "default": {
            "memberTypes": [
              "public-static-field",
              "protected-static-field",
              "private-static-field",
              "public-instance-field",
              "public-decorated-field",
              "public-abstract-field",
              "protected-instance-field",
              "protected-decorated-field",
              "protected-abstract-field",
              "private-instance-field",
              "private-decorated-field",
              "private-abstract-field",
              "static-field",
              "public-field",
              "instance-field",
              "protected-field",
              "private-field",
              "abstract-field",
              "constructor",
              "public-static-method",
              "protected-static-method",
              "private-static-method",
              "public-method",
              "protected-method",
              "private-method"
            ],
            "order": "alphabetically"
          }
      }
    ],

This doesn't produce any errors in my class, whereas I would expect 2 errors: wrong member ordering (private should go after public) and wrong alphabetic order.

no errors

Eslint is running fine, since I'm getting other errors, such as naming-convention and others


Solution

  • It appears that separating memberTypes and ordering in two categories, works. It appeared to me that the docs put the two props together, but maybe it's a bug.

    new config

    And in my editor:

    working as expected now