Skip to content

Custom ordering #2292

@thany

Description

@thany

How can I get a certain import to customly get ordered within its group?

I tried:

    "import/order": [ "error", {
      "groups": [
        [ "builtin", "external" ],
        [ "internal" ],
        [ "parent", "sibling", "index" ],
        [ "object", "type" ]
      ],
      "pathGroups": [
        {
          "pattern": "react",
          "group": "external",
          "position": "before"
        }
      ],
      "newlines-between": "always"
    } ],

Hoping that react will always be at the top of its group external, but it's not working. It's magicing up a new group, because it now requires a newline between it and any subsequent imports that are also external.

I cannot reference that new magic group:

"groups": [
  [ "react", "builtin", "external" ],
  [ "internal" ],
  [ "parent", "sibling", "index" ],
  [ "object", "type" ]
],

Pure guesswork, because the documentation doesn't say how to deal with this. This of course, produces an "unknown group" error.

And no, it's going into the builtin group, because of the "position": "before" property, because then it wouldn't require a newline between it and subsequent imports.

As stated in my previewsly created issue, pathGroupsExcludedImportTypes is super vague, and even though there's an example of it that makes it include react, it's not working as expected for me. I'm not sure if I need it at all.

Ultimately what I want to achieve is:

  • Order imports alphabetically within their groups, but;
  • Customly order certain imports to be always at the top, like react.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions