Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/brave-trees-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@biomejs/biome": patch
---

Added a new **experimental option** that allows parsing of `.html` files that contain interpolation syntax.

```json5
// biome.json
{
"html": {
// This is the new, experimental option.
"parser": {
"interpolation": true
}
}
}
```

```html
<h1>{{ $title }}</h1>
```
92 changes: 92 additions & 0 deletions crates/biome_cli/tests/cases/html.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use crate::run_cli;
use crate::snap_test::{SnapshotPayload, assert_cli_snapshot};
use biome_console::BufferConsole;
use biome_fs::MemoryFileSystem;
use bpaf::Args;
use camino::Utf8Path;

#[test]
fn should_error_when_interpolation_is_disabled() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let html_file = Utf8Path::new("file.html");
fs.insert(
html_file.into(),
r#"<div>{{ $interpolation }}</div>
"#
.as_bytes(),
);
fs.insert(
Utf8Path::new("biome.json").into(),
r#"{
"html": {
"formatter": {
"enabled": true
}
}
}"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["format", html_file.as_str()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_error_when_interpolation_is_disabled",
fs,
console,
result,
));
}

#[test]
fn should_not_error_when_interpolation_is_enabled() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let html_file = Utf8Path::new("file.html");
fs.insert(
html_file.into(),
r#"<div>{{ $interpolation }}</div>
"#
.as_bytes(),
);

fs.insert(
Utf8Path::new("biome.json").into(),
r#"{
"html": {
"parser": {
"interpolation": true
},
"formatter": {
"enabled": true
}
}
}"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["format", html_file.as_str()].as_slice()),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_not_error_when_interpolation_is_enabled",
fs,
console,
result,
));
}
1 change: 1 addition & 0 deletions crates/biome_cli/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod handle_astro_files;
mod handle_css_files;
mod handle_svelte_files;
mod handle_vue_files;
mod html;
mod included_files;
mod linter_domains;
mod linter_groups_plain;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"formatter": {
"enabled": true
}
}
}
```

## `file.html`

```html
<div>{{ $interpolation }}</div>

```

# Termination Message

```block
format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× No files were processed in the specified paths.

i Check your biome.json or biome.jsonc to ensure the paths are not ignored by the configuration.

i These paths were provided but ignored:

- file.html



```

# Emitted Messages

```block
file.html:1:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Text expressions aren't supported.

> 1 │ <div>{{ $interpolation }}</div>
│ ^^^^^^^^^^^^^^^^^^^^
2 │

i Remove it or enable the parsing using the html.parser.textExpression option.


```

```block
file.html format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Code formatting aborted due to parsing errors. To format code with errors, enable the 'formatter.formatWithErrors' option.


```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"parser": {
"interpolation": true
},
"formatter": {
"enabled": true
}
}
}
```

## `file.html`

```html
<div>{{ $interpolation }}</div>

```

# Emitted Messages

```block
Checked 1 file in <TIME>. No fixes applied.
```
6 changes: 5 additions & 1 deletion crates/biome_configuration/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ pub struct HtmlConfiguration {
pub type HtmlFormatterEnabled = Bool<false>; // Keep it disabled by default while experimental.
pub type HtmlLinterEnabled = Bool<false>;
pub type HtmlAssistEnabled = Bool<false>;
pub type HtmlParseInterpolation = Bool<false>;

/// Options that changes how the HTML parser behaves
#[derive(
Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, Bpaf, Deserializable, Merge,
)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct HtmlParserConfiguration;
pub struct HtmlParserConfiguration {
/// Enables the parsing of double text expressions such as `{{ expression }}` inside `.html` files
pub interpolation: Option<HtmlParseInterpolation>,
}

/// Options that changes how the HTML formatter behaves
#[derive(
Expand Down
66 changes: 41 additions & 25 deletions crates/biome_html_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading