Skip to content

source.organizeImports affects export object #61588

Description

Does this issue occur when all extensions are disabled?: Yes/No
Yes

  • VS Code Version: 1.99.2 (user setup)
  • OS Version: Windows_NT x64 10.0.26100

Steps to Reproduce:

With "source.OrganizeImports" = "explicit" exports of a TypeScript file are also affected.
I set up an example that looks like this:

import sample1 from './sampleImports/sample1'
import sample10 from './sampleImports/sample10'
import sample11 from './sampleImports/sample11'
import sample12 from './sampleImports/sample12'
import sample13 from './sampleImports/sample13'
import sample2 from './sampleImports/sample2'
import sample3 from './sampleImports/sample3'
import sample4 from './sampleImports/sample4'
import sample5 from './sampleImports/sample5'
import sample6 from './sampleImports/sample6'
import sample7 from './sampleImports/sample7'
import sample8 from './sampleImports/sample8'
import sample9 from './sampleImports/sample9'

export {
    sample1,
    sample2,
    sample3,
    sample4,
    sample5,
    sample6,
    sample7,
    sample8,
    sample9,
    sample10,
    sample11,
    sample12,
    sample13,
}

When I add a newline and save the file it results in this:

import sample1 from './sampleImports/sample1'
import sample10 from './sampleImports/sample10'
import sample11 from './sampleImports/sample11'
import sample12 from './sampleImports/sample12'
import sample13 from './sampleImports/sample13'
import sample2 from './sampleImports/sample2'
import sample3 from './sampleImports/sample3'
import sample4 from './sampleImports/sample4'
import sample5 from './sampleImports/sample5'
import sample6 from './sampleImports/sample6'
import sample7 from './sampleImports/sample7'
import sample8 from './sampleImports/sample8'
import sample9 from './sampleImports/sample9'


export {
    sample1, sample10,
    sample11,
    sample12,
    sample13, sample2,
    sample3,
    sample4,
    sample5,
    sample6,
    sample7,
    sample8,
    sample9
}

I expect the order of the exports to be untouched.
We are using an EsLint Plugin to sort the exports alphabetically (which is not happy with the result of the import organization), but the issue stems from the setting. Launching VS Code without any extension produces the same result.
The example can be found here: https://github.com/Zitrooone/vscode-organizeImports-test

Activity

  1. removed their assignment
    on Apr 16, 2025
  2. RyanCavanaugh commented on Apr 17, 2025

    @RyanCavanaugh
    Member

    Confirmed. No setting change required here, just need to invoke the "Organize Imports" command from the palette.

  3. idango10 commented on May 7, 2025

    @idango10
    Contributor

    Ryan Cavanaugh (@RyanCavanaugh) I noticed the behavior seems tied to the default settings for organizeImportsCollation ("ordinal") and organizeImportsNumericCollation (false). Given those defaults, it looks like the current sorting is working as designed (reference: #52115).

    That said, the issue has a Help Wanted label, were you thinking of potentially changing those defaults?

  4. jakebailey commented on May 7, 2025

    @jakebailey
    Member

    Initially when I looked at this, I thought that the problem is that the detection code isn't working (which applies when the user hasn't set anything explicitly), however rereading this, the two different blocks have two different sortings. The imports are not sorted naturally, but the exports are sorted naturally. So no matter what we're doing, we're going to resort one of the blocks.

    I can't say I like the edit that was chosen here, but, is there anything actually wrong here outside the suboptimal columns?

  5. Zitrooone commented on May 13, 2025

    @Zitrooone
    Author

    I am uncertain whether Jake Bailey (@jakebailey) 's question was directed at me, but I would like to offer my two cents on this regardless.

    Choosing sample 1 through 13 for my example was not ideal, I agree. However, I am not taking issue in the order of the keys, but with the way they are put on the same line in some instances. I would like to add, that this only happens once a certain number of keys has been reached.

    Through the issue mentioned by Idan Goshen (@idango10) I learned that the organizeImports setting is in fact supposed to affect the export as well. I see how the two are related, though the naming of the setting specifically mentions "imports" and thus I was surprised by the actual behaviour. Paired with the fact that I was not able to find any official documentation for this setting and its various sub-settings, I do think this is misleading and could likely confuse other users as well.

    To me it would be sufficient if keys remained in a one-per-line configuration, as this is important for readability in this scenario.

    Would renaming the settings or splitting import and export sorting be plausible to avoid confusion and/or conflicts with other import/export sorting?

  6. locked as resolved and limited conversation to collaborators on Dec 3, 2025
  7. RyanCavanaugh commented on Dec 3, 2025

    @RyanCavanaugh
    Member

    Closing language service bugs related to the 6.0 implementation. For more information, see #62827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions