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

Organize imports: add an option to put all absolute paths after node_modules ones #30456

Open
zbeyens opened this issue Mar 17, 2019 · 9 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@zbeyens
Copy link

zbeyens commented Mar 17, 2019

Feature Request

Add a configuration option that to sort all the absolute paths (i.e. with baseUrl = /src in jsconfig.json) after all the node_modules paths.

Reason

More and more people use alias to avoid long relative paths. It's a common practice to have first the third-party imports, then the absolute paths, and finally the relative ones.

@microsoft microsoft deleted a comment from vscodebot bot Mar 18, 2019
@mjbvz mjbvz transferred this issue from microsoft/vscode Mar 18, 2019
@mjbvz mjbvz removed their assignment Mar 18, 2019
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Mar 25, 2019
@m1heng
Copy link

m1heng commented May 3, 2020

same demand here.
We have "@/*": ["*"], in tsconfig.json, which allows us to import project wide common modules. But with current sorting, @/common/components would be on first of all imports which is against original sort logic.

@Mikoz93
Copy link

Mikoz93 commented Dec 12, 2020

@zbeyens @m1heng Is there any info on whether this is going to be supported?

@matheusmb
Copy link

Any updates? It would be great to have this feature

@medihack
Copy link

Oh yes, the current way makes this feature useless. Absolute paths are so common these days.

@danielpza
Copy link

Expected sorting

  • global node_modules imports
  • global project imports (defined by path aliases)
  • relative imports

But with path aliases (depending on the configuration), global project imports will appear first before the node_modules imports. Right now there's no distinction between global node_modules and global project imports.

tsconfig.json:

{
  "baseUrl": "./",
  "paths": { "@/*": ["./src/*"], },
}

file system:

.
├── src
│   ├── app.js
│   ├── components
│   │   ├── Button.js
│   │   └── Home.js
│   └── shared
│       ├── log.js
│       └── utils.js
└── tsconfig.json

Home.js expected order:

import React from 'react';
import { log } from '@/shared/log';
import Button from './Button';

Instead the result is:

import { log } from '@/shared/log';
import React from 'react';
import Button from './Button';

@/shared/log will be aliased after compilation to ../shared/log, so I expect it to be after react which is a node_module import

@danielpza
Copy link

@RyanCavanaugh is there any feedback I can help provide?

@tycobbb
Copy link

tycobbb commented Dec 1, 2022

same problem here, but i usually use $ the absolute-like module resolution. can't really use this feature unless it sorts based on the expanded paths, or is configurable.

@JakeBelanger
Copy link

Same request here! Has anyone found an equivalent plugin?

@danielpza
Copy link

I'm using prettier with this plugin https://github.com/IanVS/prettier-plugin-sort-imports it's pretty good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

10 participants