eslint-plugin-sort-class-members
eslint-plugin-sort-class-members copied to clipboard
Alphabetical breaks when using group
In functionfunction expandSlot(input, groups) { the following statement is found:
if (groups.hasOwnProperty(slot.group)) {
return expandSlot(groups[slot.group], groups);
} // ignore undefined groups
return [];
}
If slot has sorting info, this is discarded. This causes you to be unable to alphabetically sort groups. I'm assuming this is done to use the info from the groups array, as that one has some information that now does not need to be configured any more. A fix would be:
if (slot.group) {
if (groups.hasOwnProperty(slot.group)) {
let copy = {...groups[slot.group], ...slot};
delete copy.group;
return expandSlot(copy, groups);
} // ignore undefined groups
return [];
}
Another (separate) issue that comes to light after fixing this, is that the function
function areMembersInCorrectOrder(first, second) {
return first.acceptableSlots.some(function (a) {
return second.acceptableSlots.some(function (b) {
return a.index === b.index && areSlotsAlphabeticallySorted(a, b) ? first.name.localeCompare(second.name) <= 0 : a.index <= b.index;
});
});
}
is not suitable for anonymous members (with undefined as first.name).
A suggested fix for this would be rewriting the function areSlotsAlphabeticallySorted to become:
function areSlotsAlphabeticallySorted(a, b) {
return a.sort === 'alphabetical' && b.sort === 'alphabetical' && a.name && b.name;
}
After fixing these two issues the plugin seems to work properly for sorting members alphabetically.
Any update in this topic @bryanrsmith?
No. Happy to review a PR if anyone wants to open one.
@danielvandenberg95 Could you do a PR with the fix?