From 08e72031b8313a7cefc88155f886b72dd2f8884e Mon Sep 17 00:00:00 2001 From: zoomdong <1344492820@qq.com> Date: Thu, 7 Nov 2024 16:42:17 +0800 Subject: [PATCH] chore: update code --- CHANGELOG.md | 1 + .../ts/expressions/import_type_arguments.rs | 1 - .../import-type/import-type.ts.snap | 66 ------------------- .../tests/specs/ts/type/import_type.ts.snap | 16 +++-- .../import_type_with_resolution_mode.ts.snap | 6 +- 5 files changed, 13 insertions(+), 77 deletions(-) delete mode 100644 crates/biome_js_formatter/tests/specs/prettier/typescript/import-type/import-type.ts.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index a9f26dbd2662..f06fc96239a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ### Bug fixes - Fix [#4121](https://github.com/biomejs/biome/issues/4326), don't ident a CSS selector when has leading comments. Contributed by @fireairforce +- Fix [#4334](https://github.com/biomejs/biome/issues/4334), don't insert trailing comma on type import statement. Contributed by @fireairforce ### JavaScript APIs diff --git a/crates/biome_js_formatter/src/ts/expressions/import_type_arguments.rs b/crates/biome_js_formatter/src/ts/expressions/import_type_arguments.rs index d2c9b06e53b2..0d08ae1b6d03 100644 --- a/crates/biome_js_formatter/src/ts/expressions/import_type_arguments.rs +++ b/crates/biome_js_formatter/src/ts/expressions/import_type_arguments.rs @@ -1,6 +1,5 @@ use crate::prelude::*; use biome_formatter::write; -use biome_formatter::FormatError::SyntaxError; use biome_js_syntax::{TsImportTypeArguments, TsImportTypeArgumentsFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatTsImportTypeArguments; diff --git a/crates/biome_js_formatter/tests/specs/prettier/typescript/import-type/import-type.ts.snap b/crates/biome_js_formatter/tests/specs/prettier/typescript/import-type/import-type.ts.snap deleted file mode 100644 index 987563fb8044..000000000000 --- a/crates/biome_js_formatter/tests/specs/prettier/typescript/import-type/import-type.ts.snap +++ /dev/null @@ -1,66 +0,0 @@ ---- -source: crates/biome_formatter_test/src/snapshot_builder.rs -info: typescript/import-type/import-type.ts ---- -# Input - -```ts -// ref: https://github.com/Microsoft/TypeScript/pull/22592 - -export const x: import("./foo") = { x: 0, y: 0 }; - -export let y: import("./foo2").Bar.I = { a: "", b: 0 }; - -export let shim: typeof import("./foo2") = { - Bar: Bar2 -}; - -export interface Foo { - bar: import('immutable').Map; -} - -type X = A>; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Biome -@@ -5,11 +5,11 @@ - export let y: import("./foo2").Bar.I = { a: "", b: 0 }; - - export let shim: typeof import("./foo2") = { -- Bar: Bar2, -+ Bar: Bar2 - }; - - export interface Foo { -- bar: import("immutable").Map; -+ bar: import('immutable').Map; - } - - type X = A>; -``` - -# Output - -```ts -// ref: https://github.com/Microsoft/TypeScript/pull/22592 - -export const x: import("./foo") = { x: 0, y: 0 }; - -export let y: import("./foo2").Bar.I = { a: "", b: 0 }; - -export let shim: typeof import("./foo2") = { - Bar: Bar2 -}; - -export interface Foo { - bar: import('immutable').Map; -} - -type X = A>; -``` diff --git a/crates/biome_js_formatter/tests/specs/ts/type/import_type.ts.snap b/crates/biome_js_formatter/tests/specs/ts/type/import_type.ts.snap index 2f8396e98509..e87f96ea901b 100644 --- a/crates/biome_js_formatter/tests/specs/ts/type/import_type.ts.snap +++ b/crates/biome_js_formatter/tests/specs/ts/type/import_type.ts.snap @@ -40,19 +40,21 @@ Attribute Position: Auto ----- ```ts -type ImportType1 = typeof import('source'); +type ImportType1 = typeof import("source"); -type ImportType2 = import('source'); +type ImportType2 = import("source"); -type QualifiedImportType = typeof import('source').Qualified; +type QualifiedImportType = typeof import("source").Qualified; -type ActionLogsQ = import("longlonglonglonglonglonglonglongsource").QueryBuilder<"audit.action_logs">; +type ActionLogsQ = + import("longlonglonglonglonglonglonglongsource").QueryBuilder<"audit.action_logs">; -type LongImportType = typeof import("./long/long/long/long/long/long/long/long/path/long/long/long/long/path").default +type LongImportType = + typeof import("./long/long/long/long/long/long/long/long/path/long/long/long/long/path").default; ``` # Lines exceeding max width of 80 characters ``` - 7: type ActionLogsQ = import("longlonglonglonglonglonglonglongsource").QueryBuilder<"audit.action_logs">; - 9: type LongImportType = typeof import("./long/long/long/long/long/long/long/long/path/long/long/long/long/path").default + 8: import("longlonglonglonglonglonglonglongsource").QueryBuilder<"audit.action_logs">; + 11: typeof import("./long/long/long/long/long/long/long/long/path/long/long/long/long/path").default; ``` diff --git a/crates/biome_js_formatter/tests/specs/ts/type/import_type_with_resolution_mode.ts.snap b/crates/biome_js_formatter/tests/specs/ts/type/import_type_with_resolution_mode.ts.snap index abb5bc90e176..a736e14808c2 100644 --- a/crates/biome_js_formatter/tests/specs/ts/type/import_type_with_resolution_mode.ts.snap +++ b/crates/biome_js_formatter/tests/specs/ts/type/import_type_with_resolution_mode.ts.snap @@ -36,9 +36,9 @@ Attribute Position: Auto ----- ```ts -export type Fs = typeof import("fs", {with: { "resolution-mode": "import" }} ); +export type Fs = typeof import("fs", {with: { "resolution-mode": "import" }}); export type TypeFromRequire = - import("pkg", {with: { "resolution-mode": "require", }} ).TypeFromRequire; + import("pkg", {with: { "resolution-mode": "require", }}).TypeFromRequire; export type TypeFromImport = - import("pkg", {with: { "resolution-mode": "import", }} ).TypeFromImport; + import("pkg", {with: { "resolution-mode": "import", }}).TypeFromImport; ```