diff --git a/.changeset/expose-html-parser-vue-option.md b/.changeset/expose-html-parser-vue-option.md new file mode 100644 index 000000000000..cabdc09382b3 --- /dev/null +++ b/.changeset/expose-html-parser-vue-option.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": minor +--- + +Exposed the `html.parser.vue` configuration option. This option enables parsing of Vue syntax (directives like `v-if`, `v-bind`, etc.) in `.html` files. Most Vue users don't need to enable this option since Vue files typically use the `.vue` extension, but it can be useful for projects that embed Vue syntax in regular HTML files. diff --git a/crates/biome_cli/tests/cases/html.rs b/crates/biome_cli/tests/cases/html.rs index 517f1e6dc699..4ae300f76032 100644 --- a/crates/biome_cli/tests/cases/html.rs +++ b/crates/biome_cli/tests/cases/html.rs @@ -457,6 +457,92 @@ fn no_undeclared_classes_silent_without_style_info() { )); } +#[test] +fn should_error_when_vue_is_disabled() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let html_file = Utf8Path::new("file.html"); + fs.insert( + html_file.into(), + r#"
{{ message }}
+"# + .as_bytes(), + ); + fs.insert( + Utf8Path::new("biome.json").into(), + r#"{ + "html": { + "linter": { + "enabled": true + } + } +}"# + .as_bytes(), + ); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["lint", html_file.as_str()].as_slice()), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "should_error_when_vue_is_disabled", + fs, + console, + result, + )); +} + +#[test] +fn should_not_error_when_vue_is_enabled() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let html_file = Utf8Path::new("file.html"); + fs.insert( + html_file.into(), + r#"
{{ message }}
+"# + .as_bytes(), + ); + fs.insert( + Utf8Path::new("biome.json").into(), + r#"{ + "html": { + "parser": { + "vue": true, + "interpolation": true + }, + "linter": { + "enabled": true + } + } +}"# + .as_bytes(), + ); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["lint", 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_vue_is_enabled", + fs, + console, + result, + )); +} + #[test] fn should_lint_a_html_file() { let fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/snapshots/main_cases_html/should_error_when_vue_is_disabled.snap b/crates/biome_cli/tests/snapshots/main_cases_html/should_error_when_vue_is_disabled.snap new file mode 100644 index 000000000000..a4abfde44bb0 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_html/should_error_when_vue_is_disabled.snap @@ -0,0 +1,68 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: redactor(content) +--- +## `biome.json` + +```json +{ + "html": { + "linter": { + "enabled": true + } + } +} +``` + +## `file.html` + +```html +
{{ message }}
+ +``` + +# Termination Message + +```block +lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some errors were emitted while running checks. + + + +``` + +# Emitted Messages + +```block +file.html:1:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Vue syntax isn't enabled. Is this supposed to be a .vue file? + + > 1 │
{{ message }}
+ │ ^^^^^^^^^^^ + 2 │ + + i Remove it or enable the parsing using the html.parser.vue option. + + +``` + +```block +file.html:1:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Text expressions aren't supported. + + > 1 │
{{ message }}
+ │ ^^^^^^^^^^^^^ + 2 │ + + i Remove it or enable the parsing using the html.parser.interpolation option. + + +``` + +```block +Checked 1 file in