azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.62k stars 28 forks source link

Feature: Respect numeric separators with natural sorting #108

Open nnmrts opened 2 months ago

nnmrts commented 2 months ago

What rule do you want to change?

sort-array-includes, sort-maps, sort-objects

Describe the problem

When using numeric separators in numbers as keys, the natural order obviously breaks. For example, while 100 will be sorted after 2, 1_000 or 1_000_000 or "10,000" will not.

Code example

This issue is actually kind of two in one:

Additional comments

I think natural sorting for the rules sort-array-includes, sort-maps and sort-objects should respect number literal separators by default, and for strings there should be some kind of option.

Especially sort-array-includes and sort-maps would profit from this since they have no partition-by-comment or partition-by-new-line options, so the only "workarounds" right now are either to not use separators at all (which are enforced by unicorn/numeric-separators-style in my case at least) or to disable the rule.

Validations