Skip to content

Support sorting imports "naturally" #548

@jakebailey

Description

@jakebailey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions