-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import/order relative import sorting order changed in 2.27.0 #2682
Comments
I think this is also what @cojoclaudiu meant with #2669 (comment), but it appears to be unrelated to that issue. |
Also having issues with the |
Indeed, this seems to be broken. cc @Pearce-Ropion |
Definitely should have been a breaking change, at a minimum. |
Given that its a bug, I don't think a breaking change would have made sense since it wasn't intentional. |
@Twipped indeed, it's only a breaking change if it's intentional (and i'm not sure what would be larger than "breaking change") |
Ok, I've confirmed that this is caused by the alphabetical sortingFn introduced in 347d78b. The sorter is sorting parent imports after siblings because @ljharb What is the expected behavior for nested groups? The docs aren't very clear. In the description for
But in the example given for
And then there is nothing in the My assumption is that we should sort nested groups in element order and then alphabetically. If this is the case, the alphabetical mutations will need to be aware of the group order which will make that code much more complicated. Alternatively, we can change how the initial ranks are set by increasing the rank within nested groups in addition to just between groups. Thoughts? |
I think that the primary thing is to avoid the regression - so the default behavior should remain "whatever it did before". However, if the ideal behavior we decide on is different, we should also provide an option for that behavior. I would assume that |
Unless you want |
I believe that's what the |
Like @Pearce-Ropion, I've been relying on the fact that nested groups respect the array order and
The doc seems to imply that |
ah, fair point. We don't seem to have a way to avoid newlines between groups. or, rather - the only way we currently have to signal "treat these two groups differently" is putting them in an array. One thing that could imply is "don't newline between them, but keep their relative ordering", and another thing that could imply is "treat all groups in the array as being of equal rank". It can't imply both, so which one should it imply?
This in the docs implies to me that it should be the former. If that's what previous versions of the plugin in v2 do, then I think that's what we should go with - and if someone wants the intermingling, then we'd need a new feature request filed for that, after this bugfix is done. |
So in order to fix the regression, we would essentially need to revert 347d78b. The following uses the example The problem is that the new sorter (v2.27+) splits sorting of import paths by the In 2.26 and below, we attempt to sort on the the full import path. Thus It is worth noting that before the "alphabetization" takes place, both the parent and sibling imports have the same rank. So in both v2.26 and v2.27+, the ordering of the groups in the nested array has no affect on the final order of the imports, just that they are placed together without new lines. Instead of reverting, one option could be adding a case that specifically targets So in my mind, a real fix would be to change the alphabetical sorter to sort based on the original groups configuration option and not just the ranks. |
Seems like you have the real fix in mind :-) a PR would be appreciated! |
So the only issue with the proposed fix is that it will probably change the sorting for many people across the board since it won't just affect the sorting in this |
hmm. i think the first thing would be to address the regression without breaking any other tests. if it's going to drastically change the ordering then it's probably a breaking change and it'd have to sit for awhile. |
I've put up #2721. I think it needs more unit testing but figured I'd get the PR out there |
- kept [email protected] due to import-js/eslint-plugin-import#2682 - kept [email protected] due to bug with return types in fields/settings.ts - kept [email protected] due to issue with Merge type
Given the following rule config:
In
eslint-plugin-import
2.26, sibling imports were sorted after parent imports. In versions 2.27.0 to 2.27.5, siblings are sorted before parents.Here’s an example of previously valid, but now invalid code:
The text was updated successfully, but these errors were encountered: