Skip to content

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

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
jakebailey opened this issue Nov 21, 2022 · 5 comments · Fixed by #51634
Closed

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

jakebailey opened this issue Nov 21, 2022 · 5 comments · Fixed by #51634
Assignees
Labels
Bug A bug in TypeScript Domain: Organize Imports Issues with the organize imports feature

Comments

@jakebailey
Copy link
Member

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)
@fatcerberus
Copy link

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

@jakebailey
Copy link
Member Author

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

@andrewbranch
Copy link
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

@andrewbranch andrewbranch self-assigned this Nov 23, 2022
@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: Organize Imports Issues with the organize imports feature labels Nov 23, 2022
@andrewbranch
Copy link
Member

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

@fatcerberus
Copy link

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.

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: Organize Imports Issues with the organize imports feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants