Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Sorting Algorithm or Support Custom Sort Function #25

Open
FlorianWendelborn opened this issue Jan 25, 2021 · 2 comments
Open

Change Sorting Algorithm or Support Custom Sort Function #25

FlorianWendelborn opened this issue Jan 25, 2021 · 2 comments

Comments

@FlorianWendelborn
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants