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

Support sorting imports "naturally" #548

Open
jakebailey opened this issue Aug 11, 2023 · 2 comments
Open

Support sorting imports "naturally" #548

jakebailey opened this issue Aug 11, 2023 · 2 comments

Comments

@jakebailey
Copy link
Contributor

jakebailey commented Aug 11, 2023

Playground link

Given:

import {
  transformDeclarations,
  transformECMAScriptModule,
  Transformer,
  TransformerFactory,
  transformES5,
  transformES2015,
  transformES2016,
  transformES2017,
  transformES2018,
  transformES2019,
  transformES2020,
} from "./_namespaces/ts";

eslint-plugin-simple-import-sort sorts these like the above, which is to say naturally. TS also does this (with some configuration). dprint formats these in string order only:

import {
  transformDeclarations,
  transformECMAScriptModule,
  Transformer,
  TransformerFactory,
  transformES2015,
  transformES2016,
  transformES2017,
  transformES2018,
  transformES2019,
  transformES2020,
  transformES5,
} from "./_namespaces/ts";

It'd be great if natural sorting were an option. I'm not sure how feasible that is cross-platform, but both eslint-plugin-simple-import-sort and TS use Intl.Collator to do this, so maybe it's standardish.

@LinusU
Copy link

LinusU commented Sep 21, 2023

I think that the collator from ICU4X could be used for this, I believe that it has the same behaviour as JS Intl.Collator

@dsherret
Copy link
Member

So adding the english icu data adds about 1MB to the wasm file. I think maybe some of this could be implemented manually without needing all this language specific data. For example, the strings could be parsed into parts then compared by each part (ex. numbers could be compared by sort order of numbers).

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

3 participants