Skip to content

Organize imports doesn't keep imports in a vertical column #51615

Description

After reformatting this repo's imports as vertical sorted columns for better merge conflict handling, we noticed that running organize imports produced an odd result. Given this test:

/// <reference path="fourslash.ts" />

////import {
////    Type1,
////    Type2,
////    func4,
////    Type3,
////    Type4,
////    Type5,
////    Type7,
////    Type8,
////    Type9,
////    func1,
////    func2,
////    Type6,
////    func3,
////    func5,
////    func6,
////    func7,
////    func8,
////    func9,
////} from "foo";
////interface Use extends Type1, Type2, Type3, Type4, Type5, Type6, Type7, Type8, Type9 {}
////console.log(func1, func2, func3, func4, func5, func6, func7, func8, func9);

verify.organizeImports(
`import {
    func1,
    func2,
    func3,
    func4,
    func5,
    func6,
    func7,
    func8,
    func9,
    Type1,
    Type2,
    Type3,
    Type4,
    Type5,
    Type6,
    Type7,
    Type8,
    Type9,
} from "foo";
interface Use extends Type1, Type2, Type3, Type4, Type5, Type6, Type7, Type8, Type9 {}
console.log(func1, func2, func3, func4, func5, func6, func7, func8, func9);`
);

Organize imports gives:

import {
    func1,
    func2, func3, func4, func5,
    func6,
    func7,
    func8,
    func9, Type1,
    Type2, Type3,
    Type4,
    Type5, Type6, Type7,
    Type8,
    Type9
} from "foo";
interface Use extends Type1, Type2, Type3, Type4, Type5, Type6, Type7, Type8, Type9 {}
console.log(func1, func2, func3, func4, func5, func6, func7, func8, func9)

Activity

  1. fatcerberus commented on Nov 21, 2022

    @fatcerberus

    That’s weird, there doesn’t seem to be any rhyme or reason for how it decides to add a line break or not.

  2. jakebailey commented on Nov 21, 2022

    @jakebailey
    MemberAuthor

    I suspect this to be something related to #51301, but for reorderings.

  3. andrewbranch commented on Nov 23, 2022

    @andrewbranch
    Member

    Thanks for the fourslash test!

    there doesn’t seem to be any rhyme or reason for how it decides to add a line break or not.

    The pattern of line breaks spells out “send help, formatting-aware code transforms are hard” in Morse code

  4. andrewbranch commented on Nov 23, 2022

    @andrewbranch
    Member

    For the curious, it’s preserving the line break between elements that are consecutive both before and after the sorting.

  5. fatcerberus commented on Nov 23, 2022

    @fatcerberus

    Ah, I was confused because I assumed the string passed to verify.organizeImports was the input string, not the expected output. Everything was already in the expected order there so it seemed like it just randomly deleted some line breaks. I now realize the input string is the fourslash comments and feel dumb.

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions