Skip to content

organizeImports needs to be called twice to be stableΒ #57030

Description

@iteriani

πŸ”Ž 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

Activity

  1. iisaduan commented on Jan 16, 2024

    @iisaduan
    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

  2. rubiesonthesky commented on Feb 28, 2024

    @rubiesonthesky

    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.

  3. iisaduan commented on Feb 29, 2024

    @iisaduan
    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

  4. rubiesonthesky commented on Feb 29, 2024

    @rubiesonthesky

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

  5. iisaduan commented on Mar 9, 2024

    @iisaduan
    Member

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

  6. rubiesonthesky commented on Mar 12, 2024

    @rubiesonthesky

    Isabel Duan (@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,
      },
  7. iisaduan commented on Mar 13, 2024

    @iisaduan
    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!

  8. 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

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions