Skip to content

Question / Feature Request: Sort imports ASCII-betically / path-depth #288

@500-internal-server-error

Description

Hi, I noticed that import-x/order with the following settings:

"import-x/order": ["error", {
    "alphabetize": {
        "caseInsensitive": true,
        "order": "asc",
        "orderImportKind": "asc"
    },
    "groups": [
        ["builtin", "external"],
        ["index", "internal", "parent", "sibling"]
    ],
    "named": true,
    "newlines-between": "always"
}],

sorts the following:

import * as api from "../../api.js";      // ../../a -> 46 [46] 47  46 46 47 [ 97]
import * as utils from "../../utils.js";  // ../../u -> 46 [46] 47  46 46 47 [117]
import * as types from "./types.js";      //     ./t -> 46 [47] 116

as

  1:1  error  `../../api.js` import should occur after import of `./types.js`    import-x/order
  2:1  error  `../../utils.js` import should occur after import of `./types.js`  import-x/order

implying it sorts on the first name and not the entire string. Is there perhaps an option to sort ASCII-betically that I've missed? Perhaps "sort imports ascending" means something different to most compared to what I think it means. Is there perhaps a more granular control for "internal", "parent", and "sibling"? I suppose in some sense I'm looking to sort them based on path depth too, rather than just purely alphabetical.

I am unable to make an exact reproduction (the above example comes from a project I cannot share publicly), but the following files still demonstrate the issue described above (node_modules not included, run npm ci followed by npx eslint): zip file here, or repository here

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions