biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
14.95k stars 464 forks source link

🐛 Broken useImportType fix when "quickfix.biome": "explicit" is enabled #2268

Closed vladkrasn closed 6 months ago

vladkrasn commented 6 months ago

VS Code version

1.87.2

Extension version

2,2,2

Biome version

1.6.3

Operating system

Description

When there are many type imports, autofix on save in vscode can be buggy

Steps to reproduce

When useImportType rule is enabled, and vscode extension is configured with "quickfix.biome": "explicit", try to edit following code:

import fs, { BigIntOptions, ReadStream, lchownSync } from "fs";
import { Blob, File, Buffer} from "buffer"

const a: fs;
const b: BigIntOptions;
const c: lchownSync;
const d: Blob;
const e: File;

The result will be

import type fs from "fs";
import { type type BtIntOptions, ReadStream, type lchownSync } from "fs"
import { Blob, File, Buffer} from "buffer"

const a: fs;
const b: BigIntOptions;
const c: lchownSync;
const d: Blob;
const e: File;

You can continue pressing ctrl+s, and the code will become more and more broken. The issue seems to be exacerbated the more you mix imports that are supposed to be types and are not supposed to be them.

Expected behavior

Cli seems to be applying type to imports correctly. Vscode extension should behave like cli

Does this issue occur when using the CLI directly?

No

Logs

No response

Sec-ant commented 6 months ago

Duplicate of #1550 and #1570. I just tested your code and this will be fixed in #2237.

vladkrasn commented 6 months ago

@Sec-ant , was it supposed to be fixed in 1.6.4? While it's certainly better now, the code above is still broken after format

import type fs from "fs";
import { type BigIntOptions, lchownSync }type  from "fs";
import { type Blob, type File, } from "buffer"

const a: fs;
const b: BigIntOptions;
const c: lchownSync;
const d: Blob;
const e: File;
Sec-ant commented 6 months ago

@Sec-ant , was it supposed to be fixed in 1.6.4? While it's certainly better now, the code above is still broken after format

import type fs from "fs";
import { type BigIntOptions, lchownSync }type  from "fs";
import { type Blob, type File, } from "buffer"

const a: fs;
const b: BigIntOptions;
const c: lchownSync;
const d: Blob;
const e: File;

I added a demo to show this is fixed in https://github.com/biomejs/biome/pull/2237. I don't see any issues when quickfix.biome is enabled (see Test Plan), do you have other settings (maybe formatting) involved?

Sec-ant commented 6 months ago

Wait, I can reproduce the issue... I don't know why it works well on that PR branch... please give me some time to debug. 😢

vladkrasn commented 6 months ago

Thank you!