Skip to content

Commit 726fbd5

Browse files
committed
fix(useVueValidVBind): trim trivia when checking modifier-token text
`find_invalid_modifiers` compared `modifier_token().text()` directly, which includes trailing trivia. When a modifier was followed by `=value` the trivia was empty so this happened to work; with the Vue 3.4+ same-name shorthand the modifier can now be followed by whitespace and the self-closing `/>` instead, in which case `text()` returned e.g. `"prop "` (with the trailing space) and the valid modifier was mis-flagged as invalid. Switch to `text_trimmed()`, matching how the sibling rule `no_vue_v_on_number_values` already compares modifier names. Add test cases covering shorthand + modifier and shorthand inside a v-for.
1 parent 29c8ffa commit 726fbd5

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

crates/biome_html_analyze/src/lint/correctness/use_vue_valid_v_bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Rule for UseVueValidVBind {
139139

140140
fn find_invalid_modifiers(modifiers: &VueModifierList) -> Option<TextRange> {
141141
for modifier in modifiers {
142-
if !VALID_MODIFIERS.contains(&modifier.modifier_token().ok()?.text()) {
142+
if !VALID_MODIFIERS.contains(&modifier.modifier_token().ok()?.text_trimmed()) {
143143
return Some(modifier.range());
144144
}
145145
}

crates/biome_html_analyze/tests/specs/correctness/useVueValidVBind/valid.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<Foo v-bind:foo />
1515
<Foo v-bind:foo-bar />
1616

17+
<!-- Same-name shorthand combined with valid modifiers. -->
18+
<Foo :foo.prop />
19+
<Foo v-bind:foo.prop />
20+
21+
<!-- Same-name shorthand referencing a v-for iteration variable. -->
22+
<Foo v-for="foo of foos" :key="foo.id" :foo />
23+
1724
<!-- Valid modifiers from the rule: prop, camel, sync, attr -->
1825
<div v-bind:foo.prop="bar"></div>
1926
<div v-bind:foo.camel="bar"></div>

crates/biome_html_analyze/tests/specs/correctness/useVueValidVBind/valid.vue.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ expression: valid.vue
2020
<Foo v-bind:foo />
2121
<Foo v-bind:foo-bar />
2222
23+
<!-- Same-name shorthand combined with valid modifiers. -->
24+
<Foo :foo.prop />
25+
<Foo v-bind:foo.prop />
26+
27+
<!-- Same-name shorthand referencing a v-for iteration variable. -->
28+
<Foo v-for="foo of foos" :key="foo.id" :foo />
29+
2330
<!-- Valid modifiers from the rule: prop, camel, sync, attr -->
2431
<div v-bind:foo.prop="bar"></div>
2532
<div v-bind:foo.camel="bar"></div>

0 commit comments

Comments
 (0)