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

Unexpected import-x/sort issue in >=3.8 #351

Closed
iCrawl opened this issue Feb 17, 2025 · 5 comments
Closed

Unexpected import-x/sort issue in >=3.8 #351

iCrawl opened this issue Feb 17, 2025 · 5 comments

Comments

@iCrawl
Copy link

iCrawl commented Feb 17, 2025

Somewhere starting from 3.7.0 there seems to be some kind of bug introduced or at least a breaking change in behavior reading custom tsconfig paths.

v3.7.0...master

Previous result:

Image

No errors.

After 3.8:

Image Image

No change in userland code at all.

This obviously leads to errors where the visual editor, whether that be cursor, visual studio code or whatever wants to move those lines. But when I then try to commit and run the CLI it will complain because they shouldn't be moved around. This didn't happen in 3.7

The tsconfig paths are relatively simple as well:

...
		"paths": {
			"@/*": ["./src/*"]
		}
	},
	"include": [
		"src/**/*.ts",
		"src/**/*.tsx",
		"src/**/*.js",
		"src/**/*.jsx",
		"src/**/*.cjs",
		"src/**/*.mjs",
		"next-env.d.ts",
		".next/types/**/*.ts"
	],
...

Temporary fix for me: Downgrade and pin to 3.7.

@carlocorradini
Copy link
Contributor

Can you retry when PR #352 is merged? Thanks 🙏

@carlocorradini
Copy link
Contributor

Furthermore, import/order supports extra configuration parameters.
Using type-graphql as an example, we instruct eslint that any imports beginning with @ belong to the internal group and should be placed before.
See https://github.com/MichalLytek/type-graphql/blob/562e1da25ddd76d94d1921a28619d233a88d86bd/.eslintrc#L59 for a full example

@iCrawl
Copy link
Author

iCrawl commented Feb 17, 2025

Yes, great. The 3.8.1 release solved this issue!

Further follow-up question if you don't mind:

My current rule is set up like this:

	"import-x/order": [
		2,
		{
			alphabetize: {
				caseInsensitive: false,
				order: "asc",
			},
			groups: ["builtin", "external", "internal", "parent", "sibling", "index"],
			"newlines-between": "never",
		},
	],

Mainly to avoid hard-coding any specific "symbols" since its a shared preset. And I therefore would expect any "relative" imports to naturally come after whatever symbols I choose in my tsconfig paths, is this assumption correct?

@JounQin JounQin closed this as completed Feb 18, 2025
@carlocorradini
Copy link
Contributor

@iCrawl Personally, I'm not sure how import-x handles this, but I believe we need to add the pathGroups configuration option to guide the plugin.
Because it is used in conjunction with this resolver, and TypeScript paths are resolved with absolute paths, there may be false positives.
This is my guess, so take it with a grain of salt!

@iCrawl
Copy link
Author

iCrawl commented Feb 18, 2025

Alright, thanks!

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

3 participants