infctr / eslint-plugin-typescript-sort-keys

A linter plugin to require sorting interface and string enum keys
ISC License
143 stars 25 forks source link

Change Sorting Algorithm or Support Custom Sort Function #25

Open FlorianWendelborn opened 3 years ago

FlorianWendelborn commented 3 years ago

Currently,

UPDATE_OFFER_DETAIL: MaterialsState['offerDetail']
UPDATE_OFFERS_LIST: MaterialsState['offerList']

gets sorted because _ is considered to be after S. This unfortunately clashes with expectations and with other sorting extensions.

IMO, the most sustainable solution would be to allow passing a custom Array.prototype.sort callback as an option in the rule. Then, users can configure it exactly as they wish.

BenJackGill commented 8 months ago

I agree, because Interfaces with numbers also do not sort correctly.

This:

export interface RankCount {
  rank1: number;
  rank2To5: number;
  rank6To10: number;
  rank11To20: number;
  rank21To50: number;
  rank51Plus: number;
}

Gets incorrectly sorted to this:

export interface RankCount {
  rank1: number;
  rank11To20: number;
  rank21To50: number;
  rank2To5: number;
  rank51Plus: number;
  rank6To10: number;
}

Allowing a custom sort function would help.

BenJackGill commented 4 weeks ago

I am now using the amazing eslint-plugin-perfectionist for the same purpose.

It has alphabetical or natural sorting. Sorts everything; Interfaces, Objects, ect. Handles comments and more gracefully. Also very configurable to your exact needs.