Skip to content

Commit 08898c9

Browse files
committed
fix(html/formatter): style tag with lang
1 parent b988274 commit 08898c9

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

.changeset/sad-boxes-lead.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7917](https://github.com/biomejs/biome/issues/7917), where Biome removed the styles contained in a `<style lang="scss">`, when `experimentalFullSupportEnabled` is enabled.

crates/biome_cli/tests/cases/handle_vue_files.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,45 @@ const props: Props = { title: "Hello" };
568568
));
569569
}
570570

571+
#[test]
572+
fn full_support_enabled_and_scss_is_skipped() {
573+
let fs = MemoryFileSystem::default();
574+
let mut console = BufferConsole::default();
575+
576+
fs.insert(
577+
"biome.json".into(),
578+
r#"{ "html": { "formatter": {"enabled": true}, "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#.as_bytes(),
579+
);
580+
581+
let astro_file_path = Utf8Path::new("file.vue");
582+
fs.insert(
583+
astro_file_path.into(),
584+
r#"<html><head><title>Svelte</title></head><body></body></html>
585+
586+
<style lang="scss">
587+
#id { font-family: comic-sans } .class { background: red}
588+
</style>
589+
"#
590+
.as_bytes(),
591+
);
592+
593+
let (fs, result) = run_cli(
594+
fs,
595+
&mut console,
596+
Args::from(["check", "--write", "--unsafe", astro_file_path.as_str()].as_slice()),
597+
);
598+
599+
assert!(result.is_ok(), "run_cli returned {result:?}");
600+
601+
assert_cli_snapshot(SnapshotPayload::new(
602+
module_path!(),
603+
"full_support_enabled_and_scss_is_skipped",
604+
fs,
605+
console,
606+
result,
607+
));
608+
}
609+
571610
#[test]
572611
fn full_support_tsx() {
573612
let fs = MemoryFileSystem::default();
@@ -915,3 +954,26 @@ fn vue_compiler_macros_as_globals() {
915954
result,
916955
));
917956
}
957+
958+
#[test]
959+
fn format_vue_when_() {
960+
let fs = MemoryFileSystem::default();
961+
let mut console = BufferConsole::default();
962+
963+
let vue_file_path = Utf8Path::new("file.vue");
964+
fs.insert(vue_file_path.into(), VUE_TS_FILE_SETUP_GLOBALS.as_bytes());
965+
966+
let (fs, result) = run_cli(
967+
fs,
968+
&mut console,
969+
Args::from(["lint", vue_file_path.as_str()].as_slice()),
970+
);
971+
972+
assert_cli_snapshot(SnapshotPayload::new(
973+
module_path!(),
974+
"vue_compiler_macros_as_globals",
975+
fs,
976+
console,
977+
result,
978+
));
979+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `biome.json`
6+
7+
```json
8+
{
9+
"html": {
10+
"formatter": { "enabled": true },
11+
"linter": { "enabled": true },
12+
"experimentalFullSupportEnabled": true
13+
}
14+
}
15+
```
16+
17+
## `file.vue`
18+
19+
```vue
20+
<html>
21+
<head>
22+
<title>Svelte</title>
23+
</head>
24+
<body></body>
25+
</html>
26+
27+
<style lang="scss">
28+
#id { font-family: comic-sans } .class { background: red}
29+
</style>
30+
31+
```
32+
33+
# Emitted Messages
34+
35+
```block
36+
Checked 1 file in <TIME>. Fixed 1 file.
37+
```

crates/biome_html_formatter/src/html/auxiliary/embedded_content.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl FormatNodeRule<HtmlEmbeddedContent> for FormatHtmlEmbeddedContent {
2121
.ancestors()
2222
.skip(1)
2323
.find_map(HtmlElement::cast)?;
24-
if element.is_supported_script_tag() || element.is_style_tag() {
24+
if element.is_supported_script_tag() || element.is_supported_style_tag() {
2525
Some(node.range())
2626
} else {
2727
None

crates/biome_html_syntax/src/element_ext.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl HtmlElement {
118118
self.get_script_type().is_some_and(ScriptType::is_supported)
119119
}
120120

121+
/// It's a style tag, and it doesn't contain `scss` as `lang`
122+
pub fn is_supported_style_tag(&self) -> bool {
123+
self.is_style_tag() && !self.is_sass_lang()
124+
}
125+
121126
/// Returns the type of script for a `<script>` tag.
122127
///
123128
/// Returns `Some` [`ScriptType`] if this is a `<script>` tag, even if it

0 commit comments

Comments
 (0)