Skip to content

Commit

Permalink
challenge(formatter): don't print empty import assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Nov 15, 2023
1 parent d52c587 commit 7627189
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl FormatNodeRule<JsExportFromClause> for FormatJsExportFromClause {
write!(f, [from_token.format(), space(), source.format()])?;

if let Some(assertion) = assertion {
write!(f, [space(), assertion.format()])?;
write!(f, [assertion.format()])?;
}

FormatStatementSemicolon::new(semicolon_token.as_ref()).fmt(f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl FormatNodeRule<JsExportNamedFromClause> for FormatJsExportNamedFromClause {
]?;

if let Some(assertion) = &assertion {
write!(f, [space(), assertion.format()])?;
write!(f, [assertion.format()])?;
}

write!(f, [FormatStatementSemicolon::new(semicolon_token.as_ref())])
Expand Down
25 changes: 13 additions & 12 deletions crates/biome_js_formatter/src/js/module/import_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@ impl FormatNodeRule<JsImportAssertion> for FormatJsImportAssertion {
r_curly_token,
assertion_kind,
} = node.as_fields();

write![
f,
[assertion_kind.format(), space(), l_curly_token.format()]
]?;

if assertions.is_empty() {
let has_dangling = f.comments().has_dangling_comments(node.syntax());
write!(
f,
[
format_removed(&assertion_kind?),
format_removed(&l_curly_token?),
has_dangling.then_some(space()),
format_dangling_comments(node.syntax()).with_soft_block_indent(),
has_dangling.then_some(space()),
format_removed(&r_curly_token?),
]
)?;
)
} else {
write!(
f,
[group(&soft_space_or_block_indent(&assertions.format()))]
)?;
[
space(),
assertion_kind.format(),
space(),
l_curly_token.format(),
group(&soft_space_or_block_indent(&assertions.format())),
r_curly_token.format()
]
)
}

write!(f, [r_curly_token.format()])
}

fn fmt_dangling_comments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl FormatNodeRule<JsImportBareClause> for FormatJsImportBareClause {
write!(f, [source.format()])?;

if let Some(assertion) = assertion {
write!(f, [space(), assertion.format()])?;
write!(f, [assertion.format()])?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl FormatNodeRule<JsImportDefaultClause> for FormatJsImportDefaultClause {
]?;

if let Some(assertion) = assertion {
write!(f, [space(), assertion.format()])?;
write!(f, [assertion.format()])?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl FormatNodeRule<JsImportNamedClause> for FormatJsImportNamedClause {
write![f, [space(), from_token.format(), space(), source.format(),]]?;

if let Some(assertion) = assertion {
write!(f, [space(), assertion.format()])?;
write!(f, [assertion.format()])?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl FormatNodeRule<JsImportNamespaceClause> for FormatJsImportNamespaceClause {
]?;

if let Some(assertion) = assertion {
write!(f, [space(), assertion.format()])?;
write!(f, [assertion.format()])?;
}

Ok(())
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 7627189

Please sign in to comment.