Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fix-svelte-bind-comma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#10265](https://github.com/biomejs/biome/issues/10265): Svelte function bindings such as `bind:value={get, set}` are now parsed more precisely, so [`noCommaOperator`](https://biomejs.dev/linter/rules/no-comma-operator/) won't emit false positives for that syntax anymore.
34 changes: 32 additions & 2 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.

75 changes: 74 additions & 1 deletion crates/biome_html_factory/src/generated/syntax_factory.rs

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

107 changes: 107 additions & 0 deletions crates/biome_html_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3490,6 +3490,113 @@ impl IntoFormat<HtmlFormatContext> for biome_html_syntax::VueVSlotShorthandDirec
FormatOwnedWithRule :: new (self , crate :: vue :: auxiliary :: v_slot_shorthand_directive :: FormatVueVSlotShorthandDirective :: default ())
}
}
impl FormatRule<biome_html_syntax::SvelteBindFunctionBindingExpression>
for crate::svelte::auxiliary::bind_function_binding_expression::FormatSvelteBindFunctionBindingExpression
{
type Context = HtmlFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_html_syntax::SvelteBindFunctionBindingExpression,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_html_syntax::SvelteBindFunctionBindingExpression>::fmt(
self, node, f,
)
}
}
impl AsFormat<HtmlFormatContext> for biome_html_syntax::SvelteBindFunctionBindingExpression {
type Format<'a> = FormatRefWithRule<
'a,
biome_html_syntax::SvelteBindFunctionBindingExpression,
crate::svelte::auxiliary::bind_function_binding_expression::FormatSvelteBindFunctionBindingExpression,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::svelte::auxiliary::bind_function_binding_expression::FormatSvelteBindFunctionBindingExpression::default(),
)
}
}
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::SvelteBindFunctionBindingExpression {
type Format = FormatOwnedWithRule<
biome_html_syntax::SvelteBindFunctionBindingExpression,
crate::svelte::auxiliary::bind_function_binding_expression::FormatSvelteBindFunctionBindingExpression,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::svelte::auxiliary::bind_function_binding_expression::FormatSvelteBindFunctionBindingExpression::default(),
)
}
}
impl FormatRule<biome_html_syntax::SvelteBindFunctionBindingInitializerClause>
for crate::svelte::auxiliary::bind_function_binding_initializer_clause::FormatSvelteBindFunctionBindingInitializerClause
{
type Context = HtmlFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_html_syntax::SvelteBindFunctionBindingInitializerClause,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_html_syntax::SvelteBindFunctionBindingInitializerClause>::fmt(
self, node, f,
)
}
}
impl AsFormat<HtmlFormatContext> for biome_html_syntax::SvelteBindFunctionBindingInitializerClause {
type Format<'a> = FormatRefWithRule<
'a,
biome_html_syntax::SvelteBindFunctionBindingInitializerClause,
crate::svelte::auxiliary::bind_function_binding_initializer_clause::FormatSvelteBindFunctionBindingInitializerClause,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::svelte::auxiliary::bind_function_binding_initializer_clause::FormatSvelteBindFunctionBindingInitializerClause::default(),
)
}
}
impl IntoFormat<HtmlFormatContext>
for biome_html_syntax::SvelteBindFunctionBindingInitializerClause
{
type Format = FormatOwnedWithRule<
biome_html_syntax::SvelteBindFunctionBindingInitializerClause,
crate::svelte::auxiliary::bind_function_binding_initializer_clause::FormatSvelteBindFunctionBindingInitializerClause,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::svelte::auxiliary::bind_function_binding_initializer_clause::FormatSvelteBindFunctionBindingInitializerClause::default(),
)
}
}
impl AsFormat<HtmlFormatContext> for biome_html_syntax::AnySvelteDirectiveInitializerClause {
type Format<'a> = FormatRefWithRule<
'a,
biome_html_syntax::AnySvelteDirectiveInitializerClause,
crate::svelte::any::directive_initializer_clause::FormatAnySvelteDirectiveInitializerClause,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::svelte::any::directive_initializer_clause::FormatAnySvelteDirectiveInitializerClause::default(),
)
}
}
impl IntoFormat<HtmlFormatContext> for biome_html_syntax::AnySvelteDirectiveInitializerClause {
type Format = FormatOwnedWithRule<
biome_html_syntax::AnySvelteDirectiveInitializerClause,
crate::svelte::any::directive_initializer_clause::FormatAnySvelteDirectiveInitializerClause,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::svelte::any::directive_initializer_clause::FormatAnySvelteDirectiveInitializerClause::default(),
)
}
}
impl AsFormat<HtmlFormatContext> for biome_html_syntax::HtmlAttributeList {
type Format<'a> = FormatRefWithRule<
'a,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::prelude::*;
use biome_html_syntax::AnySvelteDirectiveInitializerClause;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatAnySvelteDirectiveInitializerClause;

impl FormatRule<AnySvelteDirectiveInitializerClause> for FormatAnySvelteDirectiveInitializerClause {
type Context = HtmlFormatContext;

fn fmt(
&self,
node: &AnySvelteDirectiveInitializerClause,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
match node {
AnySvelteDirectiveInitializerClause::HtmlAttributeInitializerClause(node) => {
node.format().fmt(f)
}
AnySvelteDirectiveInitializerClause::SvelteBindFunctionBindingInitializerClause(
node,
) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_html_formatter/src/svelte/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub(crate) mod block;
pub(crate) mod block_item;
pub(crate) mod destructured_name;
pub(crate) mod directive;
pub(crate) mod directive_initializer_clause;
pub(crate) mod each_name;
pub(crate) mod member_object;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::prelude::*;
use biome_formatter::write;
use biome_html_syntax::{
SvelteBindFunctionBindingExpression, SvelteBindFunctionBindingExpressionFields,
};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatSvelteBindFunctionBindingExpression;

impl FormatNodeRule<SvelteBindFunctionBindingExpression>
for FormatSvelteBindFunctionBindingExpression
{
fn fmt_fields(
&self,
node: &SvelteBindFunctionBindingExpression,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
let SvelteBindFunctionBindingExpressionFields {
l_curly_token,
get,
comma_token,
set,
r_curly_token,
} = node.as_fields();

write!(
f,
[group(&biome_formatter::format_args![
l_curly_token.format(),
get.format(),
comma_token.format(),
space(),
set.format(),
r_curly_token.format()
])]
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::prelude::*;
use biome_formatter::write;
use biome_html_syntax::{
SvelteBindFunctionBindingInitializerClause, SvelteBindFunctionBindingInitializerClauseFields,
};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatSvelteBindFunctionBindingInitializerClause;

impl FormatNodeRule<SvelteBindFunctionBindingInitializerClause>
for FormatSvelteBindFunctionBindingInitializerClause
{
fn fmt_fields(
&self,
node: &SvelteBindFunctionBindingInitializerClause,
f: &mut HtmlFormatter,
) -> FormatResult<()> {
let SvelteBindFunctionBindingInitializerClauseFields { eq_token, value } = node.as_fields();

write!(f, [eq_token.format(), value.format()])
}
}
2 changes: 2 additions & 0 deletions crates/biome_html_formatter/src/svelte/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub(crate) mod await_opening_block;
pub(crate) mod await_then_block;
pub(crate) mod await_then_clause;
pub(crate) mod bind_directive;
pub(crate) mod bind_function_binding_expression;
pub(crate) mod bind_function_binding_initializer_clause;
pub(crate) mod class_directive;
pub(crate) mod const_block;
pub(crate) mod curly_destructured_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::prelude::*;
use crate::shared::FmtAnySvelteBindingProperty;
use biome_formatter::{FormatRuleWithOptions, write};
use biome_html_syntax::{
AnySvelteBindingProperty, SvelteDirectiveValue, SvelteDirectiveValueFields,
AnySvelteBindingProperty, AnySvelteDirectiveInitializerClause, SvelteDirectiveValue,
SvelteDirectiveValueFields,
};

#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -56,7 +57,10 @@ impl FormatSvelteDirectiveValue {
AnySvelteBindingProperty::SvelteName(name) => name.ident_token(),
}?;

let Some(initializer) = initializer.clone() else {
let Some(AnySvelteDirectiveInitializerClause::HtmlAttributeInitializerClause(
initializer,
)) = initializer.clone()
else {
return Ok(false);
};
let Some(initializer_value) = initializer.value().ok().and_then(|v| v.string_value())
Expand Down
Loading
Loading