Repository navigation
Organize Import creates whitespace that needs to be deleted manually #40736
Description
Activity
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:- Local Imports in python considered undefined imports (#103901)
- Auto update imports on file move is extremelly slow (#102750)
- 'Add all missing imports' messes up with commas (#105214)
- Import suggestions not showing the source (only shows
Auto import from '...) (#104160) - add all missing imports with no ambiguity (#101331)
Can you share a small project that causes this. I can't reproduce it
jsgoupil commented
on Sep 24, 2020 AuthorMore actionsTry this:
import { ChangeDetectionStrategy, Component, ContentChild, EventEmitter, Input, Output, TemplateRef, AfterViewInit, ChangeDetectorRef, HostBinding, ElementRef, ViewChild } from '@angular/core'; import { Resource, ClickableResource } from '@models/resource'; import { newGuid } from '@utility/string'; import { DragulaService } from 'ng2-dragula'; interface A extends ContentChild {} interface B extends EventEmitter {} interface C extends Input {} interface D extends Output {} interface E extends TemplateRef {} interface F extends AfterViewInit {} interface G extends ChangeDetectorRef {} interface H extends HostBinding {} interface I extends ElementRef {} interface J extends Resource {} interface L extends ClickableResource {} @Component({ selector: 'wm-table', templateUrl: 'table.component.html', styleUrls: ['table.component.scss'], providers: [DragulaService], changeDetection: ChangeDetectionStrategy.OnPush }) export class TableComponent implements AfterViewInit { }Thanks Jean-Sébastien Goupil (@jsgoupil)!
Daniel Rosenwasser (@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)
- addedDomain: FormatterThe issue relates to the built-in formatterThe issue relates to the built-in formatterDomain: LS: Organize ImportsIssues with the organize imports featureIssues with the organize imports featureBugA bug in TypeScriptA bug in TypeScriptEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
on Sep 24, 2020 jsgoupil commented
on Sep 24, 2020 AuthorMore actionsMaybe 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.
- addedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
on Oct 2, 2020 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. Eli Barzilay (@elibarzilay), I can take this one if you want. /cc also Oleksandr Tarasiuk (@a-tarasyuk).
- addedRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
on Dec 11, 2020 elibarzilay commented
on Feb 13, 2021 ContributorMore actionsAndrew Branch (@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:
-
Wouldn't this get very messed up when there's an
importline that looks likeFoo, // blah blah
since the comment will get dragged along with the next import (so will appear on whatever happens to be before it, "doubly shuffled")?
-
If the source has empty lines to separate parts of the imports, then those would also move in unexpected ways; even worse with comment lines to separate such parts.
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.
-
andrewbranch commented
on Feb 16, 2021 MemberMore actionsThis should be fixed by #42630.
andrewbranch commented
on Feb 16, 2021 MemberMore actionsLooks like #41417 should have been marked as an exact duplicate of this, in fact.
elibarzilay commented
on Feb 23, 2021 ContributorMore actionsClosing this, since as Andrew Branch (@andrewbranch) notes, it's the same as #41417, and I also verified that #42630 resolves this one.
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TS Template added by Matt Bierner (@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