Skip to content

TypeScript Organize Imports inserts extra newline #36102

Description

@xROAL

TS Template added by Matt Bierner (@mjbvz)

TypeScript Version: 3.8.0-dev.20200108

Search Terms

  • Organize imports

In TypeScript / JavaScript, the command Organize Imports inserts up to two newlines if export { ... }; is at the end of a file. This does not happen with other forms of export.

  • VSCode Version: 1.41.1
  • OS Version: Windows 10 (1803)

Steps to Reproduce:

  1. Have a list / renamed export as the last line of your file, e.g.:
import { Router } from 'express';
const router = Router();
// ... other code
export { router as namedRouter }; // also happens with `export { router };`
  1. Run the Organize Imports command. It will insert a newline after the export { ... };
  2. Run the Organize Imports command 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

Activity

  1. removed their assignment
    on Jan 9, 2020
  2. Kinrany commented on Jan 25, 2020

    @Kinrany

    Should this be in 3.8?

  3. captain-yossarian commented on Feb 9, 2020

    @captain-yossarian
  4. DanielRosenwasser commented on Feb 10, 2020

    @DanielRosenwasser
    Member

    Yes

  5. DanielRosenwasser commented on Feb 10, 2020

    @DanielRosenwasser
    Member

    (Unless Eli Barzilay (@elibarzilay) has already started, but I assume you can go ahead)

  6. captain-yossarian commented on Feb 10, 2020

    @captain-yossarian

    Daniel Rosenwasser (@DanielRosenwasser) if Eli Barzilay (@elibarzilay) has already started then I will only follow this. Anyway I don't know where to start

  7. Kinrany commented on Feb 10, 2020

    @Kinrany

    I believe you'll need to fix coalesceExports in src/services/organizeImports.ts. Aside from tests, that's the only file that shows up in search.

  8. 2 remaining items

  9. elibarzilay commented on Feb 11, 2020

    @elibarzilay
    Contributor

    yossarian (@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.

  10. ahtee commented on Feb 11, 2020

    @ahtee

    Do you have any auto formatters installed currently? Something like prettier may be adding the new line.

  11. added 2 commits that reference this issue on Feb 20, 2020
    7568d0b
    2bc044e
  12. added a commit that references this issue on Mar 4, 2020
    3fe5008
  13. added a commit that references this issue on Mar 12, 2020
    0b0d6e7
  14. added a commit that references this issue on Mar 12, 2020
    bff0ddc
  15. RudeySH commented on Nov 18, 2021

    @RudeySH

    If someone out there is still having this issue, try disabling the "EditorConfig for VS Code" extension or removing insert_final_newline = true rule from .editorconfig.

  16. MM1132 commented on Jul 17, 2023

    @MM1132

    I did set "source.insertFinalNewline": false. Nothing changed.
    "source.organizeImports": true still inserts a newline at the end of imports.

  17. RudeySH commented on Jul 17, 2023

    @RudeySH

    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.

  18. MM1132 commented on Jul 17, 2023

    @MM1132

    RudeySH insertFinalNewline changes absolutely nothing. For now, disabling source.organizeImports is the only thing that makes VsCode not insert double newline after imports.

  19. bene-we commented on Sep 26, 2023

    @bene-we

    I didn't test it extensively, but for me adding the following to settings.json worked 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.

  20. rnveach commented on Jul 28, 2025

    @rnveach

    I 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.

  21. locked as resolved and limited conversation to collaborators on Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: LS: Organize ImportsIssues with the organize imports featureGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions