-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 Import creates whitespace that needs to be deleted manually #40736
Comments
(Experimental duplicate detection)
|
Can you share a small project that causes this. I can't reproduce it |
Try this:
|
Thanks @jsgoupil! @DanielRosenwasser Can we make sure this is scheduled for TS 4.1? (I have not see other reports so far, so I don't think we want to try fixing it in a 4.0 recovery build) |
Maybe there should be something a little more predictable when it comes to either putting them all the imports on one line or putting them all on different lines? It seems quite random. Also, make sure to check how many lines end up under the last import and in order to stay consistent. It had been happening forever, but I thought it would just get fixed one day :) Now that I'm doing major refactoring, this is happening a lot. |
This bug is almost definitely caused by #36688. I’m not sure off the top of my head what the best fix is, but that’s the first place to look. @elibarzilay, I can take this one if you want. /cc also @a-tarasyuk. |
@andrewbranch: I looked at this, and at the closed #40895, and I'm confused. It looks like #36688 is about preserving trivia(?) (comments & newlines, and maybe whitespace?) but I don't see how this would make sense when reordering things:
Given this, I'd expect the reasonable option to be dropping all the extras, and maybe at most do the minor thing of putting newlines in the new text if the original had any newlines, but nothing else. Clearly there's some brokenness in these cases with the extra empty lines, and I'm guessing that the #36688 doesn't account for lines being shuffled which leads to it, but even if this didn't happen, I don't see how the fixed thing would make sense given the above. |
This should be fixed by #42630. |
Looks like #41417 should have been marked as an exact duplicate of this, in fact. |
Closing this, since as @andrewbranch notes, it's the same as #41417, and I also verified that #42630 resolves this one. |
TS Template added by @mjbvz
TypeScript Version: 4.1.0-dev.20200918
Search Terms
I am not 100% sure what is the exact scenario how to reproduce this, but it happens 90% of the time. When I press ALT+SHIFT+O (Organize Imports), I get plenty of spacing in my imports.
The rules for organizing these imports seem to be all over the place, which one ends up on their own line? etc.
I always have to clean up manually.
These imports:
Become:
Video of what is happeining.
spacing-incorrect.zip
Does this issue occur when all extensions are disabled?: Yes
The text was updated successfully, but these errors were encountered: