CodeSort, a free addon to your IDE, can sort a struct's fields, an enum's variants, a switch's branches, etc. while keeping spacing, comments, and of course code, consistent.
Your code editor knows how to sort lines of text.
But it doesn't know how to sort lines of code. Sorting breaks comments and the consistency of items.
When you want to sort the fields of a class or struct, when you want to sort the branchs of a switch or match, when you want to sort the variants of an enum, you have to do it by hand. So you usually give up when the object changes.
Of course, most classes, structs, switch, enums, don't need sorting.
But when they need it, you're let with a tedious task.
That's why I built that tool you can add to your IDE and then just select the object of your choice, hit a key shortcut and have it sorted.
To install it, follow the instruction at GitHub: https://github.com/Canop/codesort
If you want more insight into the motivation and technical design, here's an article: https://dystroy.org/blog/sort-code/
Wingback