seiyab / prettier-plugin-sort-members

MIT License
5 stars 1 forks source link

Function prop in type alias sorted below everything else #40

Closed mbohgard closed 3 months ago

mbohgard commented 3 months ago

I don't know if this is a feature or not. But when "sortMembersAlphabetically": true is set I guess it would always sort alphabetically?

type Link = {
  foo: () => void;
  text: string;
  onClick: () => void;
};

will be sorted like this after formatting:

type Link = {
  text: string;
  foo: () => void;
  onClick: () => void;
};

Should be sorted like so:

type Link = {
  foo: () => void;
  onClick: () => void;
  text: string;
};

Right? This behaviour collides with for ex the following eslint setup:

"@typescript-eslint/member-ordering": [
      "warn",
      {
        "default": {
          "order": "alphabetically"
        }
      }
    ],
seiyab commented 3 months ago

Thank you for reporting. ~It's a feature. Function fields are considered as methods.~ I think there is a room of discussion. Should we consider them just fields rather than method? Or should we have an option?

seiyab commented 3 months ago

Ah, I had misunderstood. We shouldn't consider function fields as methods because this plugin respects default order of @typescript-eslint/member-ordering https://typescript-eslint.io/play/#ts=5.3.0-beta&fileType=.tsx&code=C4TwDgpgBAglC8UDeAoKUDGAuKBnYATgJYB2A5gNxpQCGAFAJQ77HlXoBGOjCAfHoVKUUAXxRA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AW0XYCNFpaA9tAAmfZgHN0UPtCGRwYAL4hFQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

seiyab commented 3 months ago

I'll fix it as a bug. (Or you can also submit a PR if you want, of course.) It can be a significant change. So I might add an option like considerFunctionAsMethod (default should be false).

seiyab commented 3 months ago

I merged https://github.com/seiyab/prettier-plugin-sort-members/pull/41. Please await for release. I want to merge other minor fixes before the next release.

seiyab commented 3 months ago

@mbohgard Shipped 0.1.2 now 🚀 . Would you try it?

mbohgard commented 3 months ago

@mbohgard Shipped 0.1.2 now 🚀 . Would you try it?

@seiyab Seems to work like a charm! Nice work and thank you for the quick response ❤️

seiyab commented 3 months ago

Thank you!