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

fix(import/order): do not compare first path segment for relative paths #2885

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mihkeleidast
Copy link

Should fix the regression in #2682.

The gist of the fix is that for relative paths, siblings always start with "." and parents always start with "..". When comparing them, it will always result in "." being first, which was the bug. The sorting based on subpath segments should start from the second path segment, when there is a possibility that one of them is different.

@mihkeleidast mihkeleidast changed the title fix(import/order): do not compare first sibling and parent path segment fix(import/order): do not compare first path segment for relative paths Sep 26, 2023
Comment on lines +179 to +182
import index from '.';
import relParent3 from '../';
import relParent1 from '../foo';
import sibling from './foo';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test confuses me. The default group order is has index last so why is it first here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this configuration ends up so that all other groups are grouped, so the imports are mingled together. Then they are sorted alphabetically, which puts this first.

That's also how it worked in 2.26.0, which is why I added it here. Ideally I would also sort it last, as that would be most logical - for that we can use either pathGroups and distinctGroups options, or your other PR.

@ljharb
Copy link
Member

ljharb commented Sep 26, 2023

Can you add the exact test case from the OP of #2682?

@mihkeleidast
Copy link
Author

@ljharb added! This was a good suggestion, as that particular case needed additional handling.

@mihkeleidast
Copy link
Author

Not sure what is going on with the failing actions, do not seem related to my changes?

@ljharb
Copy link
Member

ljharb commented Sep 27, 2023

Likely not; i'll rerun.

@acidoxee
Copy link

acidoxee commented Oct 8, 2023

Hi everyone, do you reckon this PR has a reason to be blocked? Like a lot of people, I've been sticking with v2.26.0 of this plugin since #2682 has been a thing, and I'd very much like to get back to being up-to-date and with imports in the right order 😉

@hood
Copy link

hood commented Nov 2, 2023

Any news here? PR looks fine, any blockers I can help getting rid of?

@mihkeleidast
Copy link
Author

Any news here? PR looks fine, any blockers I can help getting rid of?

I think while my fix does work for some of the reported issues, some would still not be fixed by this, e.g. #2722

I could not fix the other issues, so gave up as it does not affect my usecases as much. But probably would help if the fix would resolve all of the different issues that have been reported.

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

Successfully merging this pull request may close these issues.

None yet

5 participants