Skip to content

Commit 1de952b

Browse files
authored
Merge pull request #113 from kamadorueda/kamadorueda
feat: no space in empty containers
2 parents 1f01ac6 + 02e4ce1 commit 1de952b

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

src/rules/attr_set.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ pub fn rule(
127127
steps.push_back(crate::builder::Step::Pad);
128128
}
129129
crate::config::Layout::Wide => {
130-
steps.push_back(crate::builder::Step::Whitespace);
130+
if items_count > 0 {
131+
steps.push_back(crate::builder::Step::Whitespace);
132+
}
131133
}
132134
}
133135
steps.push_back(crate::builder::Step::Format(child.element));

src/rules/list.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ pub fn rule(
6969
));
7070
}
7171
crate::config::Layout::Wide => {
72-
steps.push_back(crate::builder::Step::Whitespace);
72+
if item_index > 1 {
73+
steps.push_back(crate::builder::Step::Whitespace);
74+
}
7375
steps
7476
.push_back(crate::builder::Step::Format(child.element));
7577
}
@@ -87,9 +89,7 @@ pub fn rule(
8789
steps.push_back(crate::builder::Step::NewLine);
8890
steps.push_back(crate::builder::Step::Pad);
8991
}
90-
crate::config::Layout::Wide => {
91-
steps.push_back(crate::builder::Step::Whitespace);
92-
}
92+
crate::config::Layout::Wide => {}
9393
}
9494
steps.push_back(crate::builder::Step::Format(child.element));
9595

src/rules/pattern.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ pub fn rule(
153153
// }
154154
let child = children.get_next().unwrap();
155155
steps.push_back(crate::builder::Step::Dedent);
156-
if !has_comments_between_curly_b && items_count <= 1 {
156+
if !has_comments_between_curly_b && items_count == 1 {
157157
steps.push_back(crate::builder::Step::Whitespace);
158+
} else if !has_comments_between_curly_b && items_count == 0 {
158159
} else {
159160
if let rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind {
160161
steps.push_back(crate::builder::Step::Token(

tests/cases/attr_set/out

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[
2-
{ }
2+
{}
33
{
44
/*
55
a
@@ -101,7 +101,7 @@
101101
a = {
102102
a = rec {
103103
a = {
104-
a = rec { a = { a = rec { a = { a = rec { a = { }; }; }; }; }; };
104+
a = rec { a = { a = rec { a = { a = rec { a = {}; }; }; }; }; };
105105
};
106106
};
107107
};

tests/cases/idioms/out

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
url = "example/${version}";
2020
};
2121
meta = with lib; {
22-
maintainers = with maintainers; [ someone ];
22+
maintainers = with maintainers; [someone];
2323
description = "something";
2424
};
2525
}

tests/cases/key_value/out

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ rec
9494
b = 1;
9595
c = 2;
9696
};
97-
n = pkgs: { };
97+
n = pkgs: {};
9898
o =
9999
{
100100
pkgs,
101101
...
102102
}:
103-
{ };
103+
{};
104104

105105
a
106106
/*
@@ -117,6 +117,6 @@ rec
117117
;
118118

119119
p =
120-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { }
120+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {}
121121
a;
122122
}

tests/cases/lambda/out

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
d
88
)
99
(
10-
{ }:
10+
{}:
1111
b:
1212
/*
1313
c
@@ -16,7 +16,7 @@
1616
)
1717
(
1818
a:
19-
{ }:
19+
{}:
2020
/*
2121
c
2222
*/
@@ -57,14 +57,14 @@
5757
)
5858
(
5959
{
60-
pkgs ? import ./.. { },
60+
pkgs ? import ./.. {},
6161
locationsXml,
6262
}:
6363
null
6464
)
6565
(
6666
a: b: c:
67-
{ }:
67+
{}:
6868
a: b: c:
6969
a
7070
)

tests/cases/lists/out

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[
2-
[ 1 ]
2+
[1]
33

44
[
55
1
66
]
77

8-
[ b d ]
8+
[b d]
99
[
1010
b
1111
d

tests/cases/pat_bind/out

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
[
2-
({ } @ a: _)
2+
({} @ a: _)
33
(
4-
{ } @
4+
{} @
55
/**/
66
a:
77
_
88
)
99
(
10-
{ }
10+
{}
1111
/**/
1212
@ a:
1313
_
1414
)
1515
(
16-
{ }
16+
{}
1717
/**/
1818
@
1919
/**/
2020
a:
2121
_
2222
)
2323

24-
(a @ { }: _)
24+
(a @ {}: _)
2525
(
2626
a @
2727
/**/
28-
{ }:
28+
{}:
2929
_
3030
)
3131
(
3232
a
3333
/**/
34-
@ { }:
34+
@ {}:
3535
_
3636
)
3737
(
3838
a
3939
/**/
4040
@
4141
/**/
42-
{ }:
42+
{}:
4343
_
4444
)
4545
]

tests/cases/pattern/out

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@ inp:
99
_
1010
)
11-
({ }: _)
11+
({}: _)
1212
({ a }: _)
1313
(
1414
{

0 commit comments

Comments
 (0)