Skip to content

Commit

Permalink
fix(js_formatter): don't insert trailing comma on type import statement
Browse files Browse the repository at this point in the history
  • Loading branch information
fireairforce committed Nov 6, 2024
1 parent 7627ab0 commit d66797e
Show file tree
Hide file tree
Showing 20 changed files with 1,658 additions and 389 deletions.
82 changes: 80 additions & 2 deletions crates/biome_js_factory/src/generated/node_factory.rs

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

129 changes: 128 additions & 1 deletion crates/biome_js_factory/src/generated/syntax_factory.rs

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

114 changes: 114 additions & 0 deletions crates/biome_js_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7809,6 +7809,120 @@ impl IntoFormat<JsFormatContext> for biome_js_syntax::TsImportType {
)
}
}
impl FormatRule<biome_js_syntax::TsImportTypeArguments>
for crate::ts::expressions::import_type_arguments::FormatTsImportTypeArguments
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_js_syntax::TsImportTypeArguments,
f: &mut JsFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_js_syntax::TsImportTypeArguments>::fmt(self, node, f)
}
}
impl AsFormat<JsFormatContext> for biome_js_syntax::TsImportTypeArguments {
type Format<'a> = FormatRefWithRule<
'a,
biome_js_syntax::TsImportTypeArguments,
crate::ts::expressions::import_type_arguments::FormatTsImportTypeArguments,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(
self,
crate::ts::expressions::import_type_arguments::FormatTsImportTypeArguments::default(),
)
}
}
impl IntoFormat<JsFormatContext> for biome_js_syntax::TsImportTypeArguments {
type Format = FormatOwnedWithRule<
biome_js_syntax::TsImportTypeArguments,
crate::ts::expressions::import_type_arguments::FormatTsImportTypeArguments,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(
self,
crate::ts::expressions::import_type_arguments::FormatTsImportTypeArguments::default(),
)
}
}
impl FormatRule<biome_js_syntax::TsImportTypeAssertion>
for crate::ts::module::import_type_assertion::FormatTsImportTypeAssertion
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_js_syntax::TsImportTypeAssertion,
f: &mut JsFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_js_syntax::TsImportTypeAssertion>::fmt(self, node, f)
}
}
impl AsFormat<JsFormatContext> for biome_js_syntax::TsImportTypeAssertion {
type Format<'a> = FormatRefWithRule<
'a,
biome_js_syntax::TsImportTypeAssertion,
crate::ts::module::import_type_assertion::FormatTsImportTypeAssertion,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(
self,
crate::ts::module::import_type_assertion::FormatTsImportTypeAssertion::default(),
)
}
}
impl IntoFormat<JsFormatContext> for biome_js_syntax::TsImportTypeAssertion {
type Format = FormatOwnedWithRule<
biome_js_syntax::TsImportTypeAssertion,
crate::ts::module::import_type_assertion::FormatTsImportTypeAssertion,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(
self,
crate::ts::module::import_type_assertion::FormatTsImportTypeAssertion::default(),
)
}
}
impl FormatRule<biome_js_syntax::TsImportTypeAssertionBlock>
for crate::ts::module::import_type_assertion_block::FormatTsImportTypeAssertionBlock
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_js_syntax::TsImportTypeAssertionBlock,
f: &mut JsFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_js_syntax::TsImportTypeAssertionBlock>::fmt(self, node, f)
}
}
impl AsFormat<JsFormatContext> for biome_js_syntax::TsImportTypeAssertionBlock {
type Format<'a> = FormatRefWithRule<
'a,
biome_js_syntax::TsImportTypeAssertionBlock,
crate::ts::module::import_type_assertion_block::FormatTsImportTypeAssertionBlock,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule :: new (self , crate :: ts :: module :: import_type_assertion_block :: FormatTsImportTypeAssertionBlock :: default ())
}
}
impl IntoFormat<JsFormatContext> for biome_js_syntax::TsImportTypeAssertionBlock {
type Format = FormatOwnedWithRule<
biome_js_syntax::TsImportTypeAssertionBlock,
crate::ts::module::import_type_assertion_block::FormatTsImportTypeAssertionBlock,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule :: new (self , crate :: ts :: module :: import_type_assertion_block :: FormatTsImportTypeAssertionBlock :: default ())
}
}
impl FormatRule<biome_js_syntax::TsImportTypeQualifier>
for crate::ts::module::import_type_qualifier::FormatTsImportTypeQualifier
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::prelude::*;
use biome_js_syntax::{TsImportTypeArguments, TsImportTypeArgumentsFields};
use biome_formatter::FormatError::SyntaxError;
use biome_formatter::write;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatTsImportTypeArguments;
impl FormatNodeRule<TsImportTypeArguments> for FormatTsImportTypeArguments {
fn fmt_fields(&self, node: &TsImportTypeArguments, f: &mut JsFormatter) -> FormatResult<()> {
let TsImportTypeArgumentsFields {
l_paren_token,
argument,
comma_token,
ts_import_type_assertion_block,
r_paren_token
} = node.as_fields();


if comma_token.is_some() && ts_import_type_assertion_block.is_some() {
write!(f, [
l_paren_token.format(),
argument.format(),
comma_token.format(),
ts_import_type_assertion_block.format(),
r_paren_token.format()
])
} else {
return Err(SyntaxError);
}
}
}
Loading

0 comments on commit d66797e

Please sign in to comment.