seiyab / prettier-plugin-sort-members

MIT License
6 stars 1 forks source link

Planned features #11

Open seiyab opened 10 months ago

seiyab commented 10 months ago

Feature request is welcome!

stormwarning commented 4 months ago

A couple features I would love 🙏

I tried to fork your plugin and strip out all the class parts, but I think I must not understand how your comparator methods work yet 😅 If these are out-of-scope for your plugin, no worries; thanks for making this!

seiyab commented 4 months ago

Thank you for your comment 😄 First, adding context about the scope, I'm wondering which should get precedence less options (See Prettier's option philosophy) or to cover more usecases.

Answering for each suggestion,

Sort only type or interface (not class)

This looks reasonable enough to me. Conflict with react/sort-comp is not desirable. Something like sortMembersIn: ['type', 'interface', 'class'] or dontSortSubclassOf: ['Component', 'PureComponent'] should exist.

Sort only alphabetically

I wonder when do we need this. But I might consider implementing it. Especially, if another one request it or clear reason (like conflict with react/sort-comp above) exist, I will accept it.

Group required members first (or optional members first)

I feel it makes sense enough. And I consider we should carefully design option. Some people can want sort by group -> sort by required or optional. Other people can want sort by required or optional -> sort by group. And more complex option related this might be requested in the future.

// sort by group -> sort by required or optional
interface A {
  n: number;
  s?: string;
  m(): void;
}

// sort by required or optional -> sort by group
interface A {
  n: number;
  m(): void;
  s?: string;
}

For schedule, it will take time because I'm busy now with my life event.

seiyab commented 3 months ago

@stormwarning Could you try skipSortForSubclassOf option in version 0.2.0-rc.0 to avoid conflict with react/sort-comp?

luber commented 1 month ago

Thanks for the plugin. It would be nice to persist empty lines between commonly named members to keep common members together:

export class TestComponent implements OnInit {
  contextMenuOpen = false;
  contextMenuItems: [];

  data: [];
  dataLoading: boolean;

  private router = inject(Router);
  private serviceA = inject(ServiceA);
  ...
}
luber commented 1 month ago

Thanks for the plugin. It would be nice to persist empty lines between commonly named members to keep common members together:

export class TestComponent implements OnInit {
  contextMenuOpen = false;
  contextMenuItems: [];

  data: [];
  dataLoading: boolean;

  private router = inject(Router);
  private serviceA = inject(ServiceA);
  ...
}

ah. looks like it works like that already... I was confused by WebStorm "Rearrange code" feature that was overwritten prettier changes :(

seiyab commented 1 month ago

Yes, it preserves empty line between members. It is Prettier's feature, not this plug-in's. But sometimes empty lines can disappear or move to unwanted place on ordering members, perhaps. Already ordered ones won't cause the problem, as far as I know.

JeyP90 commented 1 week ago

Hello!

thank you very much for this plugin! Are there any plans to add an option to read the order from @typescript-eslint/member-ordering from the eslint configuration? In my project I am not using the default configuration and it would be really great if this plugin could read the sort order that a user defines. Thanks!

seiyab commented 1 week ago

Hello.

As of now, I'm not planning user-defined highly customized ordering like tseslint. It's because following reasons.

However, I might consider implement it if many users requests and reasonable justification is provided. Or, perhaps just supporting some peset ordering is better than fully-customizable, I think. Needs discussion.