Skip to content

Commit

Permalink
challenge(formatter): don't print empty import assertion (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Nov 15, 2023
1 parent d52c587 commit 891e726
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 221 deletions.
50 changes: 6 additions & 44 deletions crates/biome_js_formatter/report.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Overall Metrics

**Average compatibility**: 91.42
**Average compatibility**: 91.65

<details>
<summary>Definition</summary>

$$average = \frac\{\sum_{file}^\{files}compatibility_\{file}}\{files}$$
</details>

**Compatible lines**: 93.04
**Compatible lines**: 93.08
<details>
<summary>Definition</summary>

Expand Down Expand Up @@ -5000,13 +5000,8 @@


# js/import-assertions/bracket-spacing/empty.js
```diff
-export * as bar from "bar.json";
+export * as bar from "bar.json" assert {};

```

**Prettier Similarity**: 0.00%
**Prettier Similarity**: 100.00%


# js/import-assertions/bracket-spacing/re-export.js
Expand All @@ -5025,22 +5020,8 @@


# js/import-assertions/empty.js
```diff
export * as foo from "foo.json";
-export * as bar from "bar.json";
-export * as baz from "baz.json" /* comment */;
+export * as bar from "bar.json" assert {};
+export * as baz from "baz.json" assert { /* comment */ };

import * as foo from "foo.json";
-import * as bar from "bar.json";
-import * as baz from "baz.json" /* comment */;
+import * as bar from "bar.json" assert {};
+import * as baz from "baz.json" assert { /* comment */ };

```

**Prettier Similarity**: 42.86%
**Prettier Similarity**: 100.00%


# js/import-assertions/multi-types.js
Expand Down Expand Up @@ -5079,13 +5060,8 @@


# js/import-attributes/bracket-spacing/empty.js
```diff
-export * as bar from "bar.json";
+export * as bar from "bar.json" with {};

```

**Prettier Similarity**: 0.00%
**Prettier Similarity**: 100.00%


# js/import-attributes/bracket-spacing/re-export.js
Expand All @@ -5104,22 +5080,8 @@


# js/import-attributes/empty.js
```diff
export * as foo from "foo.json";
-export * as bar from "bar.json";
-export * as baz from "baz.json" /* comment */;
+export * as bar from "bar.json" with {};
+export * as baz from "baz.json" with { /* comment */ };

import * as foo from "foo.json";
-import * as bar from "bar.json";
-import * as baz from "baz.json" /* comment */;
+import * as bar from "bar.json" with {};
+import * as baz from "baz.json" with { /* comment */ };

```

**Prettier Similarity**: 42.86%
**Prettier Similarity**: 100.00%


# js/import-attributes/multi-types.js
Expand Down
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 891e726

Please sign in to comment.