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

🐛 Imports are not sorted #3882

Closed
2 of 3 tasks
informeti opened this issue Sep 12, 2024 · 16 comments
Closed
2 of 3 tasks

🐛 Imports are not sorted #3882

informeti opened this issue Sep 12, 2024 · 16 comments
Labels
A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@informeti
Copy link

VS Code version

1.92.2

Extension version

2.3.0

Biome version

1.8.3

Operating system

  • Windows
  • macOS
  • Linux

Description

Formatting (on save, or manually) doesn't sort imports.
The extension also doesn't indicate any warning or error regarding import order.

However, biome check reports errors:

biome check main.ts
main.ts organizeImports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Import statements could be sorted:
  
     1    │ - import·type·{·Construct·}·from·"constructs";
     2    │ - import·{·App,·TerraformStack·}·from·"cdktf";
     3    │ - import·{·AzurermProvider·}·from·"@cdktf/provider-azurerm/lib/provider";
     4    │ - import·{·StorageBackend·}·from·"./src/storage-backend";
     5    │ - import·{·resourceGroup·}·from·"@cdktf/provider-azurerm";
        1 │ + import·{·resourceGroup·}·from·"@cdktf/provider-azurerm";
        2 │ + import·{·AzurermProvider·}·from·"@cdktf/provider-azurerm/lib/provider";
        3 │ + import·{·App,·TerraformStack·}·from·"cdktf";
        4 │ + import·type·{·Construct·}·from·"constructs";
        5 │ + import·{·StorageBackend·}·from·"./src/storage-backend";

Steps to reproduce

Write a TypeScript file with wrongly sorted imports.

Expected behavior

The extension should show a warning or error when the imports are not sorted as expected, and should offer a quickfix.

When formatting the document (manually or on save), the imports should be sorted.

Does this issue occur when using the CLI directly?

No

Link to a minimal reproduction

No response

Logs

No response

@nhedger
Copy link
Member

nhedger commented Sep 12, 2024

@ematipico
Copy link
Member

The extension should show a warning or error when the imports are not sorted as expected, and should offer a quickfix.

This is by design. Import sorting is meant to work very much like formatting: you configure your IDE/editor to run it on save, and then you can use the CLI to enforce it wherever you want

@informeti
Copy link
Author

Did you follow https://biomejs.dev/analyzer/import-sorting/#import-sorting-via-vscode-extension ?

Thank you! While it doesn't work as documented, it works as follows (i.e. without .biome):

"editor.codeActionsOnSave": {
	"source.organizeImports": "explicit"
}

@jackTabsCode
Copy link

I'm still not able to get this working on 1.9.0 or any of the 1.8.4 nightlys. The imports will sort with the CLI, but not the extension. Can someone send me their VSCode configuration to allow this?

@shayneo
Copy link

shayneo commented Sep 13, 2024

After upgrading to 1.9.0

"source.organizeImports": "explicit"

works for me.

"source.organizeImports.biome": "explicit"

does not.

my full codeActionsOnSave now is set to:

"editor.codeActionsOnSave": {
    "source.organizeImports": "explicit",
    "source.organizeImports.biome": "explicit",
    "source.fixAll.biome": "explicit",
    "quickfix.biome": "explicit"
}

as a workaround

@ematipico ematipico reopened this Sep 13, 2024
@ematipico
Copy link
Member

This is a regression. It should work with the .biome postfix.

@ematipico ematipico transferred this issue from biomejs/biome-vscode Sep 13, 2024
@ematipico ematipico added A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug labels Sep 13, 2024
@shayneo
Copy link

shayneo commented Sep 13, 2024

After upgrading to 1.9.0

"source.organizeImports": "explicit"

works for me.

"source.organizeImports.biome": "explicit"

does not.

my full codeActionsOnSave now is set to:

"editor.codeActionsOnSave": {
    "source.organizeImports": "explicit",
    "source.organizeImports.biome": "explicit",
    "source.fixAll.biome": "explicit",
    "quickfix.biome": "explicit"
}

as a workaround

correction - this isn't actually working. It's using the editor's default sort order when I do that.

@jackTabsCode
Copy link

jackTabsCode commented Sep 14, 2024

It's using the editor's default sort order when I do that.

Right, this is supplied by the Typescript language server. Biome's import sorting is different from Typescript's (for whatever reason), so while this will sort your imports in some way, biome check will fail-and the extension refuses to organize/sort imports right now.

@ematipico
Copy link
Member

I am sure the cause of the regression is #3731

@malininss
Copy link

malininss commented Sep 15, 2024

I use the 1.9 version.
"source.organizeImports.biome": "explicit" still doesn't work for me.
"source.organizeImports": "explicit" works fine

@alimehasin
Copy link

Did you follow https://biomejs.dev/analyzer/import-sorting/#import-sorting-via-vscode-extension ?

We did, still formatting via the extension fails while formatting in the cli work

@ematipico
Copy link
Member

Duplicate of #3879

It will be fixed in the next patch

@ck-euan
Copy link

ck-euan commented Sep 16, 2024

The extension should show a warning or error when the imports are not sorted as expected, and should offer a quickfix.

This is by design. Import sorting is meant to work very much like formatting: you configure your IDE/editor to run it on save, and then you can use the CLI to enforce it wherever you want

@ematipico So is there no way to automate it?
I just reenabled import sorting for my project and now have hundreds of files to go through, do I have to manually save each one? 😅

@jackTabsCode
Copy link

@ck-euan You'd run biome check --write

@ck-euan
Copy link

ck-euan commented Sep 17, 2024

@jackTabsCode For me imports never sort with the CLI I just get the error "Import statements could be sorted"

@ematipico
Copy link
Member

@jackTabsCode For me imports never sort with the CLI I just get the error "Import statements could be sorted"

You need to use --fix to actually apply the sorting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

No branches or pull requests

8 participants