Skip to content

Commit

Permalink
feat(css_formatter): CssNamespaceAtRule formatting (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov authored Mar 24, 2024
1 parent d2c70d6 commit 70bce5a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 183 deletions.
23 changes: 20 additions & 3 deletions crates/biome_css_formatter/src/css/statements/namespace_at_rule.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
use crate::prelude::*;
use biome_css_syntax::CssNamespaceAtRule;
use biome_rowan::AstNode;
use biome_css_syntax::{CssNamespaceAtRule, CssNamespaceAtRuleFields};
use biome_formatter::write;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssNamespaceAtRule;
impl FormatNodeRule<CssNamespaceAtRule> for FormatCssNamespaceAtRule {
fn fmt_fields(&self, node: &CssNamespaceAtRule, f: &mut CssFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssNamespaceAtRuleFields {
namespace_token,
prefix,
url,
semicolon_token,
} = node.as_fields();

write!(
f,
[
namespace_token.format(),
space(),
prefix.format(),
space(),
url.format(),
semicolon_token.format(),
]
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@namespace empty "";
@namespace "";
@namespace url(http://www.w3.org/1999/xhtml);
@namespace url("http://www.w3.org/1999/xhtml");
@namespace svg url(http://www.w3.org/2000/svg);
@namespace svg url("http://www.w3.org/2000/svg");
@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: css/atrule/namespace.css
---
# Input

```css
@namespace empty "";
@namespace "";
@namespace url(http://www.w3.org/1999/xhtml);
@namespace url("http://www.w3.org/1999/xhtml");
@namespace svg url(http://www.w3.org/2000/svg);
@namespace svg url("http://www.w3.org/2000/svg");
@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";

```


=============================

# Outputs

## Output 1

-----
Indent style: Tab
Indent width: 2
Line ending: LF
Line width: 80
Quote style: Double Quotes
-----

```css
@namespace empty "";
@namespace "";
@namespace url(http://www.w3.org/1999/xhtml);
@namespace url("http://www.w3.org/1999/xhtml");
@namespace svg url(http://www.w3.org/2000/svg);
@namespace svg url("http://www.w3.org/2000/svg");
@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ info: css/comments/at-rules.css
+@import /* comment 26 */'custom.css'/* comment 27 */; /* comment 28 */
+@import /* comment 29 */ url('landscape.css') /* comment 30 */ screen /* comment 31 */ and /* comment 32 */ (/* comment 33 */orientation/* comment 34 */:/* comment 35 */landscape/* comment 36 */)/* comment 37 */;

-@namespace /* comment 38 */ url(http://www.w3.org/1999/xhtml) /* comment 39 */;
+@namespace /* comment 38 */ url(http://www.w3.org/1999/xhtml) /* comment 39 */ ;
@namespace /* comment 40 */ svg /* comment 41 */ url(http://www.w3.org/2000/svg) /* comment 42 */;
@namespace /* comment 38 */ url(http://www.w3.org/1999/xhtml) /* comment 39 */;
-@namespace /* comment 40 */ svg /* comment 41 */ url(http://www.w3.org/2000/svg) /* comment 42 */;
+@namespace /* comment 40 */ /* comment 41 */ svg url(http://www.w3.org/2000/svg) /* comment 42 */;

@keyframes /* comment 43 */ slidein /* comment 44 */ {
}
Expand Down Expand Up @@ -310,8 +310,8 @@ info: css/comments/at-rules.css
@import /* comment 26 */'custom.css'/* comment 27 */; /* comment 28 */
@import /* comment 29 */ url('landscape.css') /* comment 30 */ screen /* comment 31 */ and /* comment 32 */ (/* comment 33 */orientation/* comment 34 */:/* comment 35 */landscape/* comment 36 */)/* comment 37 */;

@namespace /* comment 38 */ url(http://www.w3.org/1999/xhtml) /* comment 39 */ ;
@namespace /* comment 40 */ svg /* comment 41 */ url(http://www.w3.org/2000/svg) /* comment 42 */;
@namespace /* comment 38 */ url(http://www.w3.org/1999/xhtml) /* comment 39 */;
@namespace /* comment 40 */ /* comment 41 */ svg url(http://www.w3.org/2000/svg) /* comment 42 */;

@keyframes /* comment 43 */ slidein /* comment 44 */ {
}
Expand Down Expand Up @@ -508,7 +508,7 @@ at-rules.css:27:19 parse ━━━━━━━━━━━━━━━━━━
4: @import /* comment 6 */ url("bluish.css") /* comment 7 */ projection /* comment 8 */, /* comment 9 */ tv /* comment 10 */;
10: @import/* comment 21 */url("bluish.css")/* comment 22 */projection/* comment 23 */,/* comment 24 */tv/* comment 25 */;
12: @import /* comment 29 */ url('landscape.css') /* comment 30 */ screen /* comment 31 */ and /* comment 32 */ (/* comment 33 */orientation/* comment 34 */:/* comment 35 */landscape/* comment 36 */)/* comment 37 */;
15: @namespace /* comment 40 */ svg /* comment 41 */ url(http://www.w3.org/2000/svg) /* comment 42 */;
15: @namespace /* comment 40 */ /* comment 41 */ svg url(http://www.w3.org/2000/svg) /* comment 42 */;
51: @media /* comment 74 */ only /* comment 75 */ screen /* comment 76 */ and /* comment 77 */ (
52: /* comment 78 */ /* comment 79 */ /* comment 80 */ min-width: 320px /* comment 81 */
54: /* comment 84 */ /* comment 85 */ /* comment 86 */ max-width: 480px /* comment 87 */
Expand Down

0 comments on commit 70bce5a

Please sign in to comment.