Skip to content
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

organizeImports needs to be called twice to be stable #57030

Closed
iteriani opened this issue Jan 11, 2024 · 7 comments Β· Fixed by #57267
Closed

organizeImports needs to be called twice to be stable #57030

iteriani opened this issue Jan 11, 2024 · 7 comments Β· Fixed by #57267
Assignees
Labels
Bug A bug in TypeScript

Comments

@iteriani
Copy link

πŸ”Ž Search Terms

organizeImports

πŸ•— Version & Regression Information

  • I was unable to test this on prior versions because this seems to be a tooling issue.

⏯ Playground Link

No response

πŸ’» Code

import {abc, Abc} from 'b';
import {
  I,
  R,
  M,
} from 'a';

πŸ™ Actual behavior

This needs to be organized twice in order to be stable. The first time we get

import {I, M, R} from 'a';
import {abc, Abc} from 'b';

and the second time we get

import {I, M, R} from 'a';
import {Abc, abc} from 'b';

πŸ™‚ Expected behavior

I'd expect

import {I, M, R} from 'a';
import {Abc, abc} from 'b';

the first time around

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 12, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.5.0 milestone Jan 12, 2024
@iisaduan
Copy link
Member

I've investigated, and this behavior existed pre-5.3, and seems to be because organizeImports `s detection detects the first sort as case-insensitive, and the second sort as case-sensitive. I'm currently working on improving the detection, and currently, this issue can be manually avoided by adding

"typescript.unstable": {
     "organizeImportsIgnoreCase": true,
}

to your editor settings

@rubiesonthesky
Copy link

For me using it even twice does not usually fix the issue where VS code sometimes starts to using case insensitive sorting. I had to set typescript to version 4.9.5 to get stable sort. With that version this problem does not occur.

So eagerly waiting for fix for this before I need to update Typescript version in my project.

@iisaduan
Copy link
Member

@rubiesonthesky could you provide some more details about the cases you experience this on? I would like to make sure the issues are fixed with #57267

@rubiesonthesky
Copy link

@iisaduan I will try to check if I can replicate it and have some minimal reproduction.

@iisaduan
Copy link
Member

iisaduan commented Mar 9, 2024

@rubiesonthesky If you've been unable to get a minimal repro, can you test this version in your repository? #57267 (comment)

@rubiesonthesky
Copy link

rubiesonthesky commented Mar 12, 2024

@iisaduan My biggest problem is usually imports like these which I would like to sort case in-sensitive way. It seems that I have lost the correct config for that, because it was not needed with TS 4.9.5. I'll try to dig it up and test later.

import {BehaviorSubject, Observable, forkJoin, of} from 'rxjs';

Found the config... Will test drive it few days to see if the problem is still there.

  "typescript.unstable": {
    "organizeImportsIgnoreCase": true,
  },

@iisaduan
Copy link
Member

@rubiesonthesky To clarify, is that config the setting you already had? And how are you invoking organizeImports? (through VScode?)

import {BehaviorSubject, Observable, forkJoin, of} from 'rxjs';

(also, with this case in particular, it is already sorted in a case-sensitive way so case sensitivity = auto should always tell that it is case-sensitive.)

Thank you for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants