Open seiyab opened 10 months ago
A couple features I would love 🙏
type
or interface
(not class
) — I use the react/sort-comp
ESLint rule to sort class-based components as it's much more granularI 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!
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
orinterface
(notclass
)
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.
@stormwarning
Could you try skipSortForSubclassOf
option in version 0.2.0-rc.0 to avoid conflict with react/sort-comp
?
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);
...
}
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 :(
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.
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!
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.
Feature request is welcome!