Repository navigation
TypeScript Organize Imports inserts extra newline #36102
Description
Activity
- addedBugA bug in TypeScriptA bug in TypeScriptDomain: LS: Organize ImportsIssues with the organize imports featureIssues with the organize imports featureGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do this
on Jan 15, 2020 Should this be in 3.8?
Daniel Rosenwasser (@DanielRosenwasser) Eli Barzilay (@elibarzilay) Can I pick it up?
DanielRosenwasser commented
on Feb 10, 2020 MemberMore actionsYes
DanielRosenwasser commented
on Feb 10, 2020 MemberMore actions(Unless Eli Barzilay (@elibarzilay) has already started, but I assume you can go ahead)
captain-yossarian commented
on Feb 10, 2020 More actionsDaniel Rosenwasser (@DanielRosenwasser) if Eli Barzilay (@elibarzilay) has already started then I will only follow this. Anyway I don't know where to start
I believe you'll need to fix
coalesceExportsinsrc/services/organizeImports.ts. Aside from tests, that's the only file that shows up in search.2 remaining items
elibarzilay commented
on Feb 11, 2020 ContributorMore actionsyossarian (@captain-yossarian) I'm new so little experience with trying to run things live, instead I start with a test case for the problem and then use the debugger.
Do you have any auto formatters installed currently? Something like prettier may be adding the new line.
- added 2 commits that reference this issue
on Feb 20, 2020 - added a commit that references this issue
on Mar 4, 2020 - added a commit that references this issue
on Mar 12, 2020 - added a commit that references this issue
on Mar 12, 2020 If someone out there is still having this issue, try disabling the "EditorConfig for VS Code" extension or removing
insert_final_newline = truerule from.editorconfig.I did set
"source.insertFinalNewline": false. Nothing changed.
"source.organizeImports": truestill inserts a newline at the end of imports.Robert Reimann (@MM1132) This issue is about a problem where VS Code inserts two newlines at the end of imports, which can be solved by disabling insertFinalNewline. This solution will not make VS Code stop inserting a single newline at the end of imports, it just fixes the duplicate newline problem.
RudeySH
insertFinalNewlinechanges absolutely nothing. For now, disablingsource.organizeImportsis the only thing that makes VsCode not insert double newline after imports.I didn't test it extensively, but for me adding the following to
settings.jsonworked so far:"files.insertFinalNewline": true, "files.trimFinalNewlines": true,
With that, multiple newlines at the end of a file are being trimmed to only have a single newline, and it seems that this setting runs last.
Reacted by ngouy, Artem, Jorge Amado, William Wallace, Mika, Andreas Björkblom, Ulaş Özgüler and rnveachI just ran into this, and while the previous post does ends up saving the file correctly, you can see it is adding the new line and then subsequently removing the line quickly before the save, depending on how slow your system is.
- locked as resolved and limited conversation to collaborators
on Feb 3, 2026
TS Template added by Matt Bierner (@mjbvz)
TypeScript Version: 3.8.0-dev.20200108
Search Terms
In TypeScript / JavaScript, the command
Organize Importsinserts up to two newlines ifexport { ... };is at the end of a file. This does not happen with other forms ofexport.Steps to Reproduce:
Organize Importscommand. It will insert a newline after theexport { ... };Organize Importscommand again. It will insert another newline, resulting in two empty lines at the end of the file.Expected behavior
Only one newline is inserted / kept after the
export { ... };.Does this issue occur when all extensions are disabled?: Yes