Skip to content
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

source.organizeImports causing extra blank line #48126

Open
clabough opened this issue Mar 4, 2022 · 8 comments
Open

source.organizeImports causing extra blank line #48126

clabough opened this issue Mar 4, 2022 · 8 comments
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this
Milestone

Comments

@clabough
Copy link

clabough commented Mar 4, 2022

TS Template added by @mjbvz

TypeScript Version: 4.6.2

Search Terms

  • organize imports
  • source action

Issue Type: Bug

source.organizeImports is adding an extra blank line at the end when the typescript file only has exports. If there are any other lines (e.g. code) after the exports, then the extra line does not get added.

VS Code version: Code 1.65.0 (b5205cc8eb4fbaa726835538cd82372cc0222d43, 2022-03-02T11:12:08.962Z)
OS version: Windows_NT x64 10.0.19044
Restricted Mode: No

Extensions: none

In this project, I've created a new default Angular project and added an index.ts to show the issue.

VSCode-OrganizeImports

@mjbvz mjbvz transferred this issue from microsoft/vscode Mar 4, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Mar 4, 2022

Minimal repo file:

import 'fs';

This returns the following code edit:

[Trace  - 23:49:58.180] <semantic> Response received: organizeImports (276). Request took 2 ms. Success: true 
Result: [
    {
        "fileName": "/Users/matb/projects/san/index.tsx",
        "textChanges": [
            {
                "start": {
                    "line": 1,
                    "offset": 1
                },
                "end": {
                    "line": 1,
                    "offset": 13
                },
                "newText": "import 'fs';\n"
            }
        ]
    }
]

@mjbvz mjbvz removed their assignment Mar 4, 2022
@mjbvz mjbvz removed the new release label Mar 4, 2022
@RyanCavanaugh RyanCavanaugh added the Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it label Mar 5, 2022
@RyanCavanaugh
Copy link
Member

It seems to top out at 2 trailing newlines, so the process at least reaches a fixed point. This doesn't seem like a priority.

@clabough
Copy link
Author

clabough commented Mar 5, 2022

@RyanCavanaugh If you're using the linting rule 'no-multiple-empty-lines', then saving causes a violation of that rule, and without knowing about the 'File:Save without formatting', you end up in an endless loop.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this and removed Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it labels Mar 5, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 5, 2022
@RyanCavanaugh RyanCavanaugh reopened this Mar 5, 2022
@RyanCavanaugh RyanCavanaugh added the Domain: Refactorings e.g. extract to constant or function, rename symbol label Mar 5, 2022
@clabough
Copy link
Author

clabough commented Mar 7, 2022

I just found this suggestion.

#41494

Like @RyanCavanaugh said, ignoring one line would be challenging, but I think something like // organize-imports-disable at the top to disable for the whole file would solve 95% of the issues.

@TheDevMinerTV
Copy link

Having the same issue here, it's causing us to fail our formatting checking...

Would love for this to get fixed

@lortonx
Copy link

lortonx commented Apr 4, 2024

bump, my prettier conflicts with this

@pflannery
Copy link

pflannery commented Jun 9, 2024

edit: Correction thought this was a closed issue.

@RyanCavanaugh Please consider re-opening for a future fix.

I have this issue too when using vscode source.organizeImports feature and requiring no new lines at the bottom of files of the source code.

I have to manually execute the hotkey in all my files. If the file is an export file (e.g. a rollup file or main export file) then I have to also remove the newline it generates. Its painful.

Enabling source.organizeImport leaves me in an internal save changes loop.

Example export file that always has a newline appended when organizing imports:

export * from './iServiceCollection';
export * from './iServiceCollectionFactory';
export * from './iServiceProvider';

@jwbth
Copy link

jwbth commented Jun 22, 2024

In the short term it can be fixed by #36102 (comment).

pflannery added a commit to pflannery/TypeScript that referenced this issue Jun 23, 2024
pflannery added a commit to pflannery/TypeScript that referenced this issue Jun 23, 2024
pflannery added a commit to pflannery/TypeScript that referenced this issue Jun 23, 2024
pflannery added a commit to pflannery/TypeScript that referenced this issue Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

7 participants