bryanrsmith / eslint-plugin-sort-class-members

An ESLint rule for enforcing consistent ES6 class member order
119 stars 21 forks source link

sortInterfaces: function properties are not treated as methods #97

Open EvgenyOrekhov opened 1 year ago

EvgenyOrekhov commented 1 year ago

There are 2 notations for methods:

  1. shorthand method: baz(): string
  2. function property: baz: () => string

sortInterfaces: true works with shorthand method signature, but not with function property signature.

Minimal reproducible case:

    "sort-class-members/sort-class-members": [
      "error",
      {
        "order": [
          "[properties]",
          "[methods]"
        ],
        "sortInterfaces": true
      }
    ]
interface Foo {
  baz: () => string;
  bar: string;
}

Expected: warning "Expected property bar to come before method baz"

Actual: no warning

EvgenyOrekhov commented 1 year ago

BTW, method-signature-style rule uses function property style by default, so function property style might be more common.

ygrandgirard commented 6 months ago

I am not sure whether the plugin should enforce this behavior or not. There already is propertyType to achieve pretty much the same thing in a configurable way:

{
    order: [
        '[properties]'
        { type: 'property', propertyType: '...' }
        '[methods]'
    ]
}

However, it does not seem to work with interfaces as it is. I will try to create a PR to fix this soon.

ygrandgirard commented 1 hour ago

Hello @EvgenyOrekhov! My PR was just merged and released as part of v1.21.0. Does it solve your issue?