diff --git a/.changeset/brave-trees-push.md b/.changeset/brave-trees-push.md new file mode 100644 index 000000000000..b463b8e1cb17 --- /dev/null +++ b/.changeset/brave-trees-push.md @@ -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 +

{{ $title }}

+``` diff --git a/crates/biome_cli/tests/cases/html.rs b/crates/biome_cli/tests/cases/html.rs new file mode 100644 index 000000000000..d7a27a71318e --- /dev/null +++ b/crates/biome_cli/tests/cases/html.rs @@ -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#"
{{ $interpolation }}
+"# + .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#"
{{ $interpolation }}
+"# + .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, + )); +} diff --git a/crates/biome_cli/tests/cases/mod.rs b/crates/biome_cli/tests/cases/mod.rs index 5d2bf39d274b..3616fba4755c 100644 --- a/crates/biome_cli/tests/cases/mod.rs +++ b/crates/biome_cli/tests/cases/mod.rs @@ -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; diff --git a/crates/biome_cli/tests/snapshots/main_cases_html/should_error_when_interpolation_is_disabled.snap b/crates/biome_cli/tests/snapshots/main_cases_html/should_error_when_interpolation_is_disabled.snap new file mode 100644 index 000000000000..937db2201b3d --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_html/should_error_when_interpolation_is_disabled.snap @@ -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 +
{{ $interpolation }}
+ +``` + +# 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 │
{{ $interpolation }}
+ │ ^^^^^^^^^^^^^^^^^^^^ + 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