seiyab / prettier-plugin-sort-members

MIT License
8 stars 2 forks source link

Conflict with @typescript-eslint/member-ordering #57

Closed Tsury closed 1 month ago

Tsury commented 1 month ago

Hello.

I have this code:

export class SomeClass {
  @someDecorator
  private static someStaticMethod() {
    //
  }

  private static someOtherStaticMethod = () => {
    //
  };
}

I'm getting this issue:

Member someOtherStaticMethod should be declared before all private decorated method definitions.

When I move someOtherStaticMethod manually to be before someStaticMethod, the issue it resolved, but when I format with prettier, it reverts it and moves someOtherStaticMethod to be after someStaticMethod, making the issue appear again.

eslint config: '@typescript-eslint/member-ordering': 'error',

prettier config: "plugins": ["prettier-plugin-sort-members"]

How can I resolve this issue? Thanks in advance.

seiyab commented 1 month ago

Hi, thank you for reporting the issue. It's a bug. The default ordering of this plugin should be compatible with @typescript-eslint/member-ordering's default. I'm considering to fix it.

I found that @typescript-eslint/member-ordering itself looks inconsistent around static and decorated... For instance methods, it requires decorated ones get former. On the other hand, for static methods, it requires decorated ones get latter... Anyway, I'm considering that we have to design this plugin to have capability with @typescript-eslint/member-ordering's default.

export class SomeClass {
  @someDecorator
  private static someStaticMethod() {
    //
  }

  // error
  private static someOtherStaticMethod(){
    //
  };
}

export class SomeClassB {
  @someDecorator
  private someStaticMethod() {
    //
  }

  // OK
  private someOtherStaticMethod() {
    //
  };
}
seiyab commented 1 month ago

I'm wondering whether we should have an option to select precedence between consistency and compatibility.

seiyab commented 1 month ago

@Tsury Would you try new version 0.2.1-rc.1?

Tsury commented 1 month ago

Hey @seiyab, thanks for the rapid response! I just tried 0.2.1-rc.1 and it seems to behave exactly the same for me - when eslint complains about the non-decorated static methods being below the non-decorated static method, and I manually move it, upon formatting it sends them down below again.

Was I required to configure anything maybe?

seiyab commented 1 month ago

@Tsury Thank you for trying. Would you reload IDE?

Tsury commented 1 month ago

Eh. Reloading the IDE did resolve the issue - sorry about that, and thank you so much both for this project and both for your quick response!

Tsury commented 1 month ago

I'll leave it to you to close it as you see fit.

seiyab commented 1 month ago

Thank you for reporting it and verify fix! Close as resolved 👍