dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

Support sorting imports "naturally"

Open jakebailey opened this issue 2 years ago • 2 comments

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.

jakebailey avatar Aug 11 '23 18:08 jakebailey

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

LinusU avatar Sep 21 '23 12:09 LinusU