Skip to content

Commit 272632f

Browse files
authored
feat: indentation for vue and svelte files (#7330)
1 parent 72a8b02 commit 272632f

35 files changed

Lines changed: 220 additions & 161 deletions

.changeset/dull-drinks-switch.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Updated the formatting of `.svelte` and `.vue` files. Now the indentation of the JavaScript blocks matches Prettier's:
6+
7+
```diff
8+
<script>
9+
- import Component from "./Component"
10+
+ import Component from "./Component"
11+
</script>
12+
```

crates/biome_cli/tests/cases/handle_svelte_files.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const hello : string = "world";
2323
</script>
2424
<div></div>"#;
2525

26-
const SVELTE_TS_CONTEXT_MODULE_FILE_FORMATTED: &str = r#"<script context="module" lang="ts">
27-
import Button from "./components/Button.svelte";
28-
const hello: string = "world";
29-
</script>
30-
<div></div>"#;
31-
3226
const SVELTE_CARRIAGE_RETURN_LINE_FEED_FILE_UNFORMATTED: &str =
3327
"<script>\r\n const a = \"b\";\r\n</script>\r\n<div></div>";
3428

@@ -176,12 +170,6 @@ fn format_svelte_ts_context_module_files_write() {
176170

177171
assert!(result.is_ok(), "run_cli returned {result:?}");
178172

179-
assert_file_contents(
180-
&fs,
181-
svelte_file_path,
182-
SVELTE_TS_CONTEXT_MODULE_FILE_FORMATTED,
183-
);
184-
185173
assert_cli_snapshot(SnapshotPayload::new(
186174
module_path!(),
187175
"format_svelte_ts_context_module_files_write",

crates/biome_cli/tests/cases/handle_vue_files.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,18 @@ statement ( ) ;
1111
</script>
1212
<template></template>"#;
1313

14-
const VUE_IMPLICIT_JS_FILE_FORMATTED: &str = r#"<script>
15-
import { something } from "file.vue";
16-
statement();
17-
</script>
18-
<template></template>"#;
19-
2014
const VUE_EXPLICIT_JS_FILE_UNFORMATTED: &str = r#"<script lang="js">
2115
import { something } from "file.vue";
2216
statement ( ) ;
2317
</script>
2418
<template></template>"#;
2519

26-
const VUE_EXPLICIT_JS_FILE_FORMATTED: &str = r#"<script lang="js">
27-
import { something } from "file.vue";
28-
statement();
29-
</script>
30-
<template></template>"#;
31-
3220
const VUE_TS_FILE_UNFORMATTED: &str = r#"<script setup lang="ts">
3321
import { type something } from "file.vue";
3422
const hello : string = "world";
3523
</script>
3624
<template></template>"#;
3725

38-
const VUE_TS_FILE_FORMATTED: &str = r#"<script setup lang="ts">
39-
import { type something } from "file.vue";
40-
const hello: string = "world";
41-
</script>
42-
<template></template>"#;
43-
4426
const VUE_JS_FILE_NOT_LINTED: &str = r#"<script setup lang="js">
4527
a == b;
4628
delete a.c;
@@ -155,8 +137,6 @@ fn format_vue_implicit_js_files_write() {
155137

156138
assert!(result.is_ok(), "run_cli returned {result:?}");
157139

158-
assert_file_contents(&fs, vue_file_path, VUE_IMPLICIT_JS_FILE_FORMATTED);
159-
160140
assert_cli_snapshot(SnapshotPayload::new(
161141
module_path!(),
162142
"format_vue_implicit_js_files_write",
@@ -215,8 +195,6 @@ fn format_vue_explicit_js_files_write() {
215195

216196
assert!(result.is_ok(), "run_cli returned {result:?}");
217197

218-
assert_file_contents(&fs, vue_file_path, VUE_EXPLICIT_JS_FILE_FORMATTED);
219-
220198
assert_cli_snapshot(SnapshotPayload::new(
221199
module_path!(),
222200
"format_vue_explicit_js_files_write",
@@ -296,8 +274,6 @@ fn format_vue_ts_files_write() {
296274

297275
assert!(result.is_ok(), "run_cli returned {result:?}");
298276

299-
assert_file_contents(&fs, vue_file_path, VUE_TS_FILE_FORMATTED);
300-
301277
assert_cli_snapshot(SnapshotPayload::new(
302278
module_path!(),
303279
"format_vue_ts_files_write",

crates/biome_cli/tests/commands/format.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,18 @@ statement ( ) ;
4747
</script>
4848
<div></div>"#;
4949

50-
const SVELTE_IMPLICIT_JS_FILE_FORMATTED: &str = r#"<script>
51-
import { something } from "file.svelte";
52-
statement();
53-
</script>
54-
<div></div>"#;
55-
5650
const SVELTE_EXPLICIT_JS_FILE_UNFORMATTED: &str = r#"<script lang="js">
5751
import { something } from "file.svelte";
5852
statement ( ) ;
5953
</script>
6054
<div></div>"#;
6155

62-
const SVELTE_EXPLICIT_JS_FILE_FORMATTED: &str = r#"<script lang="js">
63-
import { something } from "file.svelte";
64-
statement();
65-
</script>
66-
<div></div>"#;
67-
6856
const SVELTE_TS_FILE_UNFORMATTED: &str = r#"<script setup lang="ts">
6957
import { type something } from "file.svelte";
7058
const hello : string = "world";
7159
</script>
7260
<div></div>"#;
7361

74-
const SVELTE_TS_FILE_FORMATTED: &str = r#"<script setup lang="ts">
75-
import { type something } from "file.svelte";
76-
const hello: string = "world";
77-
</script>
78-
<div></div>"#;
79-
8062
const APPLY_TRAILING_COMMAS_BEFORE: &str = r#"
8163
const a = [
8264
longlonglonglongItem1longlonglonglongItem1,
@@ -2996,8 +2978,6 @@ fn format_svelte_implicit_js_files_write() {
29962978

29972979
assert!(result.is_ok(), "run_cli returned {result:?}");
29982980

2999-
assert_file_contents(&fs, svelte_file_path, SVELTE_IMPLICIT_JS_FILE_FORMATTED);
3000-
30012981
assert_cli_snapshot(SnapshotPayload::new(
30022982
module_path!(),
30032983
"format_svelte_implicit_js_files_write",
@@ -3056,8 +3036,6 @@ fn format_svelte_explicit_js_files_write() {
30563036

30573037
assert!(result.is_ok(), "run_cli returned {result:?}");
30583038

3059-
assert_file_contents(&fs, svelte_file_path, SVELTE_EXPLICIT_JS_FILE_FORMATTED);
3060-
30613039
assert_cli_snapshot(SnapshotPayload::new(
30623040
module_path!(),
30633041
"format_svelte_explicit_js_files_write",
@@ -3143,8 +3121,6 @@ fn format_svelte_ts_files_write() {
31433121

31443122
assert!(result.is_ok(), "run_cli returned {result:?}");
31453123

3146-
assert_file_contents(&fs, svelte_file_path, SVELTE_TS_FILE_FORMATTED);
3147-
31483124
assert_cli_snapshot(SnapshotPayload::new(
31493125
module_path!(),
31503126
"format_svelte_ts_files_write",

crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_astro_files.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/biome_cli/tests/snap_test.rs
3-
expression: content
3+
expression: redactor(content)
44
---
55
## `file.astro`
66

crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_astro_files_write.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/biome_cli/tests/snap_test.rs
3-
expression: content
3+
expression: redactor(content)
44
---
55
## `file.astro`
66

crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/format_stdin_write_successfully.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/biome_cli/tests/snap_test.rs
3-
expression: content
3+
expression: redactor(content)
44
---
55
# Input messages
66

crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_write_successfully.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ var foo: string = "";
1919

2020
```block
2121
<script context="module" lang="ts">
22-
import Button from "./components/Button.svelte";
23-
import { Form } from "./components/Form.svelte";
22+
import Button from "./components/Button.svelte";
23+
import { Form } from "./components/Form.svelte";
2424
25-
debugger;
26-
statement();
27-
var foo: string = "";
25+
debugger;
26+
statement();
27+
var foo: string = "";
2828
</script>
2929
<div></div>
3030
```

crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/check_stdin_write_unsafe_successfully.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var foo: string = "";
1919

2020
```block
2121
<script context="module" lang="ts">
22-
statement();
23-
var _foo: string = "";
22+
statement();
23+
var _foo: string = "";
2424
</script>
2525
<div></div>
2626
```

crates/biome_cli/tests/snapshots/main_cases_handle_svelte_files/format_stdin_successfully.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/biome_cli/tests/snap_test.rs
3-
expression: content
3+
expression: redactor(content)
44
---
55
# Input messages
66

@@ -16,8 +16,8 @@ const hello : string = "world";
1616

1717
```block
1818
<script context="module" lang="ts">
19-
import Button from "./components/Button.svelte";
20-
const hello: string = "world";
19+
import Button from "./components/Button.svelte";
20+
const hello: string = "world";
2121
</script>
2222
<div></div>
2323
```

0 commit comments

Comments
 (0)