azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.64k stars 29 forks source link

Bug: sort-classes does not follow order in groups for private instance method #62

Closed MohnJcAfee closed 9 months ago

MohnJcAfee commented 9 months ago

Describe the bug

When given a custom sort order for sort-classes, private methods (with #) syntax are not sorted properly but rather the # seems to be interpreted as just another character.

Code example

Order set in eslint config:

"perfectionist/sort-classes": [
  "error",
  {
    "type": "natural",
    "order": "asc",
    "groups": [
      "static-property",
      "private-property",
      "property",
      "constructor",
      "method",
      "private-method",
      "static-method",
      "other"
    ]
  }
]

The following unsorted class:

class MyUnsortedClass {
  someOtherProperty

  someProperty = 1

  constructor() {}

  static #aPrivateStaticMethod () {}

  #somePrivateProperty

  #someOtherPrivateProperty = 2

  static someStaticProperty = 3

  static #someStaticPrivateProperty = 4

  aInstanceMethod () {}

  static aStaticMethod () {}

  #aPrivateInstanceMethod () {}

}

results in the following order:

class MyUnsortedClass {
  static #someStaticPrivateProperty = 4

  static someStaticProperty = 3

  #someOtherPrivateProperty = 2

  #somePrivateProperty

  someOtherProperty

  someProperty = 1

  constructor() {}

  #aPrivateInstanceMethod () {}

  aInstanceMethod () {}

  static #aPrivateStaticMethod () {}

  static aStaticMethod () {}

}

the private instance method is above the instance method despite the group having a different order. It should be:

aInstanceMethod () {}

#aPrivateInstanceMethod () {}

ESLint version

8.48.0

ESLint Plugin Perfectionist version

1.5.1

Additional comments

it seems the # is not interpreted as "private" but rather just as a character in sorting static/regular methods and properties

Validations

azat-io commented 9 months ago

Thanks for the issue! It's good idea, i think it will be implemented soon.

azat-io commented 9 months ago

Fixed in c00ac107411d86c25a0cf5a0b87fa2c2845c8176.

Release is coming soon.

azat-io commented 8 months ago

Released in v2.0.0