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

Custom ordering #2292

Closed
thany opened this issue Nov 4, 2021 · 1 comment · Fixed by #2395
Closed

Custom ordering #2292

thany opened this issue Nov 4, 2021 · 1 comment · Fixed by #2395

Comments

@thany
Copy link

thany commented Nov 4, 2021

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.
@ljharb
Copy link
Member

ljharb commented Nov 4, 2021

The rule currently doesn't allow what you want.

It seems reasonable to allow a custom pathGroup to be able to opt out of having a newline inserted around it, but I'm not sure what that schema would look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants