Skip to content

source.organizeImports must not remove empty line between import #24324

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

Closed
mjbvz opened this issue May 22, 2018 · 8 comments
Closed

source.organizeImports must not remove empty line between import #24324

mjbvz opened this issue May 22, 2018 · 8 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@mjbvz
Copy link
Contributor

mjbvz commented May 22, 2018

From @nikolay-borzov on May 22, 2018 12:37

Usually imports are organized in groups separated by empty line (e.g. node packages, services, components). I think that organizeImports should respect existing groups and perform organizing within each group.

  • VSCode Version: 1.23.1
  • OS Version: Windows 10 x64

Steps to Reproduce:

  1. Set user settings:
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
  source.organizeImports": true
}
  1. Create .ts file
import path from 'path'

import fs from 'fs'

const currentDir = path.resolve(__dirname)
const data = fs.readdirSync(currentDir)
  1. Press Ctrl+S

  2. Result:

import fs from 'fs'
import path from 'path'

const currentDir = path.resolve(__dirname)
const data = fs.readdirSync(currentDir)

Does this issue occur when all extensions are disabled?: Yes (Disabled TSLint and Prettier)

Copied from original issue: microsoft/vscode#50277

@mhegazy
Copy link
Contributor

mhegazy commented May 22, 2018

looks like a duplicate of #22914

@mhegazy mhegazy added Duplicate An existing issue was already created and removed javascript labels May 22, 2018
@mjbvz
Copy link
Contributor Author

mjbvz commented May 22, 2018

I believe #22914 tracks removing the newlines while this issue is about preserving the newlines and the import groups they define

@mhegazy
Copy link
Contributor

mhegazy commented May 22, 2018

ah. sorry misread the issue. thanks.

I do not think this is something we can easily accomplish, since the imports themselves move, and some even are completely removed with their contents merged into other imports; it is not clear how we can figure out what is a group and what is not in the midst of these transformations.

@mhegazy mhegazy added Design Limitation Constraints of the existing architecture prevent this from being fixed and removed Duplicate An existing issue was already created labels May 22, 2018
@mjbvz
Copy link
Contributor Author

mjbvz commented May 22, 2018

Agreed. Given the work required, unless there are many users requesting this, this kind of more advanced sorting seems like a better fit for an extension

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@taoqf
Copy link

taoqf commented Feb 19, 2019

I have to disable source.organizeImports for the same reason.

@indapublic
Copy link

No solution?

@dobeerman
Copy link

We'd like to keep some packages on top of all imports and keep the rest are organised. For instance, "source-map-support/register", datadog tracer, etc must be stick to the top. But it is not possible with source.organizeImports enabled.

The issue is 6 year old, so I'm quite surprised there is no solution so far 😞

Am i missed something? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

6 participants