Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sortInterfaces: function properties are not treated as methods #97

Open
EvgenyOrekhov opened this issue Oct 16, 2023 · 3 comments
Open

Comments

@EvgenyOrekhov
Copy link

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
Copy link
Author

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

@ygrandgirard
Copy link
Contributor

ygrandgirard commented Apr 11, 2024

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants