-
Notifications
You must be signed in to change notification settings - Fork 12.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
Feature request: disable organize import on specific lines #41494
Comments
Having the same issue when importing global css files that needs to be kept in a specific order :
They get reorganized in the wrong order, which leads me to having to disable the organize import feature for the all project, which is a shame :( Being able to ignore a file would solve issues like this. |
Would be a good feature to be implemented. |
Running into the same problem with this feature, stylings importing in the incorrect order, and polyfills moving down the import chain, reference. |
Would be great to have such option. I'm running into this issue when dotenv config needs to be executed before specific imports. |
Just run into this in this context angular/angular#40977 (comment) |
+1 for this feature. In Next.js, import order matters when importing CSS files. |
+1 for this awesome feature! I need this importing CSS files in React. |
+1 i need 'reflect-metadata' to be the first lib in my file |
@RyanCavanaugh What kind of Feedback are we waiting for? This feature is very important when we use reorganize import automatically on save. It happens often in projects that we must import something before other imports. I have to use 'Save without formatting' every time I work on a file where the import order is important, it is boring and also difficult to remember for all team members that they should not change the order of imports in that specific file Here are some use cases
|
I need it to respect requirements of https://github.com/welldone-software/why-did-you-render
|
+1 for this feature. I need it to maintain order of imports when using FullCalendar in Next JS projects with next-transpile-modules package |
What does it mean to disable the sorting of one item in a list? e.g. if I wrote import E from "E";
// organize-imports-disable-next-line
import D from "D";
import C from "C";
import B from "B";
import A from "A"; and "sort" this list, what is the new order? |
Good point. Perhaps pinning an import to the top of the file, as opposed to disabling organizing it, then? Then the others can be normally sorted? |
I would even say 'pinning one or multiple imports to the top of the file without changing their order'. I believe that this would handle all the use cases that were cited here. Something like: import E from "E";
import D from "D";
// organize-imports-disable-above
import C from "C";
import B from "B";
import A from "A"; |
It's probably easier to disable for file, in which case this feature request could cover this scenario microsoft/vscode#35350 |
Any updates on this one? In Inversify, I must have import "reflect-metadata"; as the top import for my server.ts file. Changing this breaks the whole server. |
+1 we also need polyfills at the top of the import list. |
+1 |
Can the people +1ing this answer the above question? #41494 (comment) |
Causes 3 groups that each need to be sorted independently:
When processing imports you start with one import group and at each comment:
In:
|
I too would like this. e.g. I need to make sure |
What would folks think if we implemented the rule that each block of newline-contiguous imports sorted independently? import c from "C";
import d from "D";
import a from "A";
import b from "B"; would sort to import c from "C";
import a from "A";
import b from "B";
import d from "D"; |
@RyanCavanaugh My concern with the proposed contiguous-imports solution is how it would effect automatic imports. Which group would automatic imports be added to? It gets more confusing when you have more than two groups. I like the previously proposed solution of disabling above/below as others have mentioned since it seems that users typically want imports pinned to the top or the bottom (can't speak for everyone, but this has been my experience). It also makes it clear that automatic imports would be added in between the import b from "B"
import a from "A"
// organize-imports-disable-above
import e from "E"
import f from "F" // <-- automatic imports get added and organized in this group
import g from "G"
// organize-imports-disable-below
import d from "D"
import c from "C" |
I am in favor of @RyanCavanaugh's suggestion because this gives benefits in multiple real world cases I am aware of. |
I like @RyanCavanaugh's proposal a lot. It's clean and easy to understand. No need for ugly comments. @robertn702 Automatic imports get added to the last group, which is what is needed in 99% of the cases, as the first groups are usually polyfills. If it's not the case, you can always move the import manually. |
Yes, sticking entirely new auto-imports at the bottom was the simple method we came up with in our design meeting; of course if it's not a fully "new" import (e.g. adding a new import from an already imported module), there's no ambiguity, which helps. |
Happy to take a PR for "automatically create sort groups based on newlines" behavior |
hi @RyanCavanaugh, based on your suggestion above, I create an solution for sort groups based on newlines. It would be great to have your feedback 😀 (if you think it is ok, I will add more test cases). PR: #48330 |
Is this integrated into recent versions of VS Code? |
No, this is in TS 4.7; the release candidate came out yesterday. If you install the nightly JS/TS extension in VS Code (or install the RC and set VS Code to use the workspace TS), you should see this working. |
Hi. Thanks for the amazing update ! Do you know if there is a way to enable such the same parameter to export organizing? By default, "organizeImports" also organize exports. Example - Before export d from "D";
export a from "A";
export b from "B";
export c from "C"; //depends on D Current behaviour export a from "A";
export b from "B";
export c from "C"; //depends on D which is not currently exported => causes a build error
export d from "D"; Desired behaviour export a from "A";
export b from "B";
export d from "D";
export c from "C"; //depends on D => no error Edit : if needed, i can move this request to another issue? |
@Rlamotte please open a new issue. Thanks! |
NextJs 13 app directory needs 'use client' as the 1st line but VC Code moves until after the import statements. How do stop the move? |
To avoid the following issue #42873, I import some "unused" types like this import type { Unused } from "some-dep" But I am also using I do not want it to remove that line One fix I have is that I write the following to explicitly use the type type Unuseds = Unused | ... Now |
I like using the auto organize imports on save feature (
"editor.codeActionsOnSave": {"source.organizeImports": true}
onsettings.json
), but I had to disable it for some specific cases for which the import organization would break my code.For instance, take this React JS file
The React Polyfill import specifically requires to be the first line in the file to provide Internet Explorer compatibility sucessfully. However, if you save the file with import organizing active, the
import React from 'react';
line jumps to the top, breaking React Polyfill's functionality. I had to disable the functionality in mysettings.json
to work around the issue.What I propose is some kind of comment-disabling feature, like so:
This has also been mentioned as an issue previously: microsoft/vscode#78553 (comment)
The text was updated successfully, but these errors were encountered: