Typescript: source.organizeImports must not remove empty line between import

Created on 22 May 2018  路  6Comments  路  Source: microsoft/TypeScript

_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_

Design Limitation

Most helpful comment

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

All 6 comments

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

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  路  3Comments

Zlatkovsky picture Zlatkovsky  路  3Comments

siddjain picture siddjain  路  3Comments

wmaurer picture wmaurer  路  3Comments

seanzer picture seanzer  路  3Comments