diff --git a/.changeset/fix-vue-directive-expression-parsing.md b/.changeset/fix-vue-directive-expression-parsing.md new file mode 100644 index 000000000000..5e0818b6932b --- /dev/null +++ b/.changeset/fix-vue-directive-expression-parsing.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Fixed a bug where Vue directive attribute values like `v-bind:class="{'dynamic': true}"` were incorrectly parsed as JavaScript statements instead of expressions. Object literals inside directive values like `:class`, `v-if`, and `v-html` are now correctly parsed as expressions, preventing spurious parse errors. diff --git a/crates/biome_html_analyze/tests/spec_tests.rs b/crates/biome_html_analyze/tests/spec_tests.rs index 8c3ce3baace6..1dc7740a138c 100644 --- a/crates/biome_html_analyze/tests/spec_tests.rs +++ b/crates/biome_html_analyze/tests/spec_tests.rs @@ -4,8 +4,8 @@ use biome_html_parser::parse_html; use biome_html_syntax::{HtmlFileSource, HtmlLanguage}; use biome_rowan::AstNode; use biome_test_utils::{ - CheckActionType, assert_diagnostics_expectation_comment, assert_errors_are_absent, - code_fix_to_string, create_analyzer_options, diagnostic_to_string, + CheckActionType, analyze_with_workspace, assert_diagnostics_expectation_comment, + assert_errors_are_absent, code_fix_to_string, create_analyzer_options, diagnostic_to_string, has_bogus_nodes_or_empty_slots, parse_test_path, register_leak_checker, scripts_from_json, write_analyzer_snapshot, }; @@ -22,6 +22,11 @@ fn run_test(input: &'static str, _: &str, _: &str, _: &str) { let input_file = Utf8Path::new(input); let file_name = input_file.file_name().unwrap(); + // Skip options files — they are configuration, not test inputs + if file_name.ends_with(".options.json") { + return; + } + let (group, rule) = parse_test_path(input_file); if rule == "specs" { panic!("the test file must be placed in the {rule}/// directory"); @@ -62,18 +67,7 @@ fn run_test(input: &'static str, _: &str, _: &str, _: &str) { ); } } else { - let Ok(source_type) = input_file.try_into() else { - return; - }; - analyze_and_snap( - &mut snapshot, - &input_code, - source_type, - filter, - file_name, - input_file, - CheckActionType::Lint, - ); + snapshot = analyze_with_workspace(input_file, input_code, group, rule); }; insta::with_settings!({ diff --git a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html index f176c0356c62..61e64a027e90 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html +++ b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html @@ -3,7 +3,6 @@ Picture of friend. Image of friend. PhOtO of friend. -{"photo"} piCTUre of friend. imAGE of friend. image of cool person diff --git a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html.snap b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html.snap index be84855affb5..875b1c331e52 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.html.snap @@ -9,7 +9,6 @@ expression: invalid.html Picture of friend. Image of friend. PhOtO of friend. -{"photo"} piCTUre of friend. imAGE of friend. image of cool person @@ -17,8 +16,6 @@ expression: invalid.html ``` -_Note: The parser emitted 2 diagnostics which are not shown here._ - # Diagnostics ``` invalid.html:2:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -63,7 +60,7 @@ invalid.html:4:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ > 4 │ Image of friend. │ ^^^^^^^^^^^^^^^^^^ 5 │ PhOtO of friend. - 6 │ {"photo"} + 6 │ piCTUre of friend. i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -79,8 +76,8 @@ invalid.html:5:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ 4 │ Image of friend. > 5 │ PhOtO of friend. │ ^^^^^^^^^^^^^^^^^^ - 6 │ {"photo"} - 7 │ piCTUre of friend. + 6 │ piCTUre of friend. + 7 │ imAGE of friend. i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -88,16 +85,16 @@ invalid.html:5:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.html:7:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.html:6:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. + 4 │ Image of friend. 5 │ PhOtO of friend. - 6 │ {"photo"} - > 7 │ piCTUre of friend. + > 6 │ piCTUre of friend. │ ^^^^^^^^^^^^^^^^^^^^ - 8 │ imAGE of friend. - 9 │ image of cool person + 7 │ imAGE of friend. + 8 │ image of cool person i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -105,16 +102,16 @@ invalid.html:7:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.html:8:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.html:7:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. - 6 │ {"photo"} - 7 │ piCTUre of friend. - > 8 │ imAGE of friend. - │ ^^^^^^^^^^^^^^^^^^ - 9 │ image of cool person - 10 │ imAGE of friend. + 5 │ PhOtO of friend. + 6 │ piCTUre of friend. + > 7 │ imAGE of friend. + │ ^^^^^^^^^^^^^^^^^^ + 8 │ image of cool person + 9 │ imAGE of friend. i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -122,16 +119,16 @@ invalid.html:8:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.html:9:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.html:8:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. - 7 │ piCTUre of friend. - 8 │ imAGE of friend. - > 9 │ image of cool person + 6 │ piCTUre of friend. + 7 │ imAGE of friend. + > 8 │ image of cool person │ ^^^^^^^^^^^^^^^^^^^^^^ - 10 │ imAGE of friend. - 11 │ + 9 │ imAGE of friend. + 10 │ i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -139,15 +136,15 @@ invalid.html:9:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.html:10:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.html:9:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. - 8 │ imAGE of friend. - 9 │ image of cool person - > 10 │ imAGE of friend. + 7 │ imAGE of friend. + 8 │ image of cool person + > 9 │ imAGE of friend. │ ^^^^^^^^^^^^^^^^^^ - 11 │ + 10 │ i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. diff --git a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue index d6c6d26f3a3c..6566effb5017 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue +++ b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue @@ -3,7 +3,6 @@ Picture of friend. Image of friend. PhOtO of friend. -{"photo"} piCTUre of friend. imAGE of friend. image of cool person diff --git a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue.snap b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue.snap index 928d0ff71a0d..0a4c985d000c 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/invalid.vue.snap @@ -3,21 +3,18 @@ source: crates/biome_html_analyze/tests/spec_tests.rs expression: invalid.vue --- # Input -```html +```vue Photo of friend. Picture of friend. Image of friend. PhOtO of friend. -{"photo"} piCTUre of friend. imAGE of friend. image of cool person ``` -_Note: The parser emitted 2 diagnostics which are not shown here._ - # Diagnostics ``` invalid.vue:2:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @@ -62,7 +59,7 @@ invalid.vue:4:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ > 4 │ Image of friend. │ ^^^^^^^^^^^^^^^^^^ 5 │ PhOtO of friend. - 6 │ {"photo"} + 6 │ piCTUre of friend. i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -78,8 +75,8 @@ invalid.vue:5:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ 4 │ Image of friend. > 5 │ PhOtO of friend. │ ^^^^^^^^^^^^^^^^^^ - 6 │ {"photo"} - 7 │ piCTUre of friend. + 6 │ piCTUre of friend. + 7 │ imAGE of friend. i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -87,16 +84,16 @@ invalid.vue:5:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.vue:7:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.vue:6:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. + 4 │ Image of friend. 5 │ PhOtO of friend. - 6 │ {"photo"} - > 7 │ piCTUre of friend. + > 6 │ piCTUre of friend. │ ^^^^^^^^^^^^^^^^^^^^ - 8 │ imAGE of friend. - 9 │ image of cool person + 7 │ imAGE of friend. + 8 │ image of cool person i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -104,16 +101,16 @@ invalid.vue:7:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.vue:8:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.vue:7:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. - 6 │ {"photo"} - 7 │ piCTUre of friend. - > 8 │ imAGE of friend. - │ ^^^^^^^^^^^^^^^^^^ - 9 │ image of cool person - 10 │ + 5 │ PhOtO of friend. + 6 │ piCTUre of friend. + > 7 │ imAGE of friend. + │ ^^^^^^^^^^^^^^^^^^ + 8 │ image of cool person + 9 │ i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. @@ -121,15 +118,15 @@ invalid.vue:8:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━ ``` ``` -invalid.vue:9:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.vue:8:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Avoid the words "image", "picture", or "photo" in img element alt text. - 7 │ piCTUre of friend. - 8 │ imAGE of friend. - > 9 │ image of cool person - │ ^^^^^^^^^^^^^^^^^^^^^^ - 10 │ + 6 │ piCTUre of friend. + 7 │ imAGE of friend. + > 8 │ image of cool person + │ ^^^^^^^^^^^^^^^^^^^^^^ + 9 │ i Screen readers announce img elements as "images", so it is not necessary to redeclare this in alternative text. diff --git a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/valid.vue.snap b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/valid.vue.snap index bfc23be26a0b..94858bc8bfdc 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/valid.vue.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/noRedundantAlt/valid.vue.snap @@ -3,7 +3,7 @@ source: crates/biome_html_analyze/tests/spec_tests.rs expression: valid.vue --- # Input -```html +```vue foo diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAltText/vue/valid.vue.snap b/crates/biome_html_analyze/tests/specs/a11y/useAltText/vue/valid.vue.snap index 0b495869cea6..2dbcac4bca93 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAltText/vue/valid.vue.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/useAltText/vue/valid.vue.snap @@ -3,7 +3,7 @@ source: crates/biome_html_analyze/tests/spec_tests.rs expression: valid.vue --- # Input -```html +```vue diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/invalid.astro.snap b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/invalid.astro.snap index e48117c9cae9..cab7e6ae23c4 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/invalid.astro.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/invalid.astro.snap @@ -1,10 +1,9 @@ --- source: crates/biome_html_analyze/tests/spec_tests.rs -assertion_line: 83 expression: invalid.astro --- # Input -```html +```astro --- // Astro frontmatter --- diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro index 4a805afa0664..3296c667f7a9 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro @@ -1,5 +1,5 @@ --- -// Astro frontmatter +// should not generate diagnostics --- diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro.snap b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro.snap index ca412d20f6a9..3c87566117f5 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro.snap @@ -1,12 +1,11 @@ --- source: crates/biome_html_analyze/tests/spec_tests.rs -assertion_line: 83 expression: valid.astro --- # Input -```html +```astro --- -// Astro frontmatter +// should not generate diagnostics --- diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/invalid.svelte.snap b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/invalid.svelte.snap index d97c337b854d..09ea6bed22c9 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/invalid.svelte.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/invalid.svelte.snap @@ -3,7 +3,7 @@ source: crates/biome_html_analyze/tests/spec_tests.rs expression: invalid.svelte --- # Input -```html +```svelte diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte index e8fb306d85f5..22f8e60e8688 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte @@ -1,3 +1,4 @@ + diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte.snap b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte.snap index 679d7053efa0..72d8a409767a 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/svelte/valid.svelte.snap @@ -3,7 +3,8 @@ source: crates/biome_html_analyze/tests/spec_tests.rs expression: valid.svelte --- # Input -```html +```svelte + diff --git a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/vue/invalid.vue.snap b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/vue/invalid.vue.snap index 459c31674613..6adede7686d3 100644 --- a/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/vue/invalid.vue.snap +++ b/crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/vue/invalid.vue.snap @@ -3,7 +3,7 @@ source: crates/biome_html_analyze/tests/spec_tests.rs expression: invalid.vue --- # Input -```html +```vue