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

Regression in nested group order after v2.26 #2909

Open
jraoult opened this issue Oct 26, 2023 · 10 comments
Open

Regression in nested group order after v2.26 #2909

jraoult opened this issue Oct 26, 2023 · 10 comments

Comments

@jraoult
Copy link

jraoult commented Oct 26, 2023

This is a follow-up to #2854 (comment). I'm stuck in 2.26 because of a regression introduced in 2.27. Multiple reverts and updates try to fix the regression, but I still have a few spots where the regression shows up:

This is my configuration:

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

and typically, this used to pass in 2.26:

import { isNotNull } from "option-t/esm/Nullable";

import { combineNullables } from "../util/combineNullables.js";
import type { BigFraction } from "./BigFraction.js";
import { FRACTION_ZERO } from "./fraction.js";

but fails after 2.26 with message: ../util/combineNullables.js import should occur after import of ./fraction.js

@yndajas
Copy link
Contributor

yndajas commented Oct 26, 2023

Per #2854 (comment), it seems the issue here is wanting to use groups to enforce line breaks AND wanting the order to matter within groups, whereas by default the point of groups is to define multiple import types that must be grouped together but within which group their type is irrelevant (and optionally to add a new line after each group)

It seems there are few different configuration needs here:

  • new line between groups: boolean (already supported)
  • order by type within groups: boolean (not yet supported; default false)

The second one has changed a few times with recent releases and the documentation is slightly confusing since it says both "The enforced order is the same as the order of each element in a group" and "They can be mingled together", which are arguably in opposition and causing different understandings?

@jraoult I think what you're after would essentially be true and true in the configuration above?

@ljharb is it worth adding an extra configuration option to support these different use cases? I don't mind having a go at that, although I can't guarantee a quick turnaround!

@jraoult
Copy link
Author

jraoult commented Oct 26, 2023

@yndajas, I appreciate you taking the time to look at that, and it seems like your proposal could work.

I want to stress that I was happy with how it was pre-2.27. I'm reporting the regression in the following minor version jumps. The ordering inside the nested group changed from 2.27 and it should either be a major version jump or it is a regression and should be restored to the behaviour pre-2.27.

I realise I'm probably nitpicking too much around semver semantic here but maybe it is easier to roll back to previous behaviour than introducing a new configuration?

@yndajas
Copy link
Contributor

yndajas commented Oct 26, 2023

I realise I'm probably nitpicking too much around semver semantic here but maybe it is easier to roll back to previous behaviour than introducing a new configuration?

In terms of restoring semantic versioning principles, perhaps it would be a case of reverting the default (and clarifying the expected default in the docs), but I think combining that with a config extension might be useful to support both interpretations of the docs so it doesn't feel like a regression in the opposite direction 😅

@ljharb
Copy link
Member

ljharb commented Oct 26, 2023

I think that it's important to restore whatever default behavior in v2.26 wasn't broken, and I'm fine with adding options to keep the otherwise-reverted functionality.

@hood
Copy link

hood commented Nov 2, 2023

I confirm this behaviour is totally unexpected on my side too.

My suggested import order post 2.27.0:

import ItemA from "./ItemA";
import ItemC from "../../ItemC";
import ItemB from "../ItemB";

@yndajas
Copy link
Contributor

yndajas commented Nov 2, 2023

I confirm this behaviour is totally unexpected on my side too.

My suggested import order post 2.27.0:

import ItemA from "./ItemA";
import ItemC from "../../ItemC";
import ItemB from "../ItemB";

Is that [sibling, parent]? What was it pre-2.27.0?

@hood
Copy link

hood commented Nov 2, 2023

Pre-2.27.0 imports were sorted by depth (as expected):

import ItemC from "../../ItemC";
import ItemB from "../ItemB";
import ItemA from "./ItemA";

Config excerpt:

// ...
"import/order": [
    "error",

    {
      "groups": [
        ["builtin", "external"],
        [
          "internal",
          "parent",
          "sibling",
          "index",
          "object",
          "type",
          "unknown"
        ]
      ],
      "newlines-between": "always",
      "alphabetize": {
        "order": "asc",
        "caseInsensitive": true
      }
    }
  ],
// ...

I also see discussion about this topic here: #2396 (comment)

Which led to this PR (which is yet to be merged): #2885

And other related issues: #2682

@yndajas
Copy link
Contributor

yndajas commented Nov 2, 2023

@hood wow there are so many threads on this! It's difficult to synthesise all this and work out what's the original behaviour and what needs adding as a feature to avoid breaking the breaking changes 😅 seems like the documentation has confused others too

@hood
Copy link

hood commented Nov 2, 2023

The PR I linked fixed the issue at least partially. It'd be a good starting point to get that merged first, and then proceed to focus on restoring the remaining wrong behaviours IMHO. At its current state the plugin is not behaving in a predictable manner, and it's not backwards compatible, forcing pretty much everyone using relative imports on 2.26.0. I can help if needed.

@hood
Copy link

hood commented Nov 3, 2023

There is also another PR addressing this: #2721

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

No branches or pull requests

4 participants