Skip to content

Commit 5d871d7

Browse files
committed
Keep trailing comment in { and [
This is a partial revert of 5bb0639 The change introduced there is now redundant because we catch that specific corner case more precisely in the parser nowadays, so it's reasonable to revert
1 parent 1f2589c commit 5d871d7

File tree

13 files changed

+52
-98
lines changed

13 files changed

+52
-98
lines changed

src/Nixfmt/Pretty.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ prettySet _ (krec, paropen@(LoneAnn _), Items [], parclose@Ann{preTrivia = []})
177177
sep = if sourceLine paropen /= sourceLine parclose then hardline else hardspace
178178
-- Singleton sets are allowed to fit onto one line,
179179
-- but apart from that always expand.
180-
prettySet wide (krec, paropen@Ann{trailComment = post}, binders, parclose) =
180+
prettySet wide (krec, paropen, binders, parclose) =
181181
pretty (fmap (,hardspace) krec)
182-
<> pretty (paropen{trailComment = Nothing})
183-
<> surroundWith sep (nest $ pretty post <> prettyItems binders)
182+
<> pretty paropen
183+
<> surroundWith sep (nest $ prettyItems binders)
184184
<> pretty parclose
185185
where
186186
sep =
@@ -223,9 +223,9 @@ prettyTerm (List paropen@Ann{trailComment = Nothing} (Items []) parclose@Ann{pre
223223
sep = if sourceLine paropen /= sourceLine parclose then hardline else hardspace
224224
-- General list
225225
-- Always expand if len > 1
226-
prettyTerm (List paropen@Ann{trailComment = post} items parclose) =
227-
pretty (paropen{trailComment = Nothing})
228-
<> surroundWith sur (nest $ pretty post <> prettyItems items)
226+
prettyTerm (List paropen items parclose) =
227+
pretty paropen
228+
<> surroundWith sur (nest $ prettyItems items)
229229
<> pretty parclose
230230
where
231231
-- If the brackets are on different lines, keep them like that

test/diff/attr_set/out-pure.nix

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[
22
{ }
3-
{
4-
# a
3+
{ # a
54
}
65
{ a = 1; }
76
{ a = 1; }
@@ -21,25 +20,21 @@
2120
{
2221
b = 1; # c
2322
}
24-
{
25-
# a
23+
{ # a
2624
b = 1;
2725
}
28-
{
29-
# a
26+
{ # a
3027
b = 1; # c
3128
}
3229

3330
rec { c = 1; }
3431
rec {
3532
c = 1; # d
3633
}
37-
rec {
38-
# b
34+
rec { # b
3935
c = 1;
4036
}
41-
rec {
42-
# b
37+
rec { # b
4338
c = 1; # d
4439
}
4540
rec # a
@@ -51,13 +46,11 @@
5146
c = 1; # d
5247
}
5348
rec # a
54-
{
55-
# b
49+
{ # b
5650
c = 1;
5751
}
5852
rec # a
59-
{
60-
# b
53+
{ # b
6154
c = 1; # d
6255
}
6356

test/diff/attr_set/out.nix

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[
22
{ }
3-
{
4-
# a
3+
{ # a
54
}
65
{ a = 1; }
76
{
@@ -24,25 +23,21 @@
2423
{
2524
b = 1; # c
2625
}
27-
{
28-
# a
26+
{ # a
2927
b = 1;
3028
}
31-
{
32-
# a
29+
{ # a
3330
b = 1; # c
3431
}
3532

3633
rec { c = 1; }
3734
rec {
3835
c = 1; # d
3936
}
40-
rec {
41-
# b
37+
rec { # b
4238
c = 1;
4339
}
44-
rec {
45-
# b
40+
rec { # b
4641
c = 1; # d
4742
}
4843
rec # a
@@ -54,13 +49,11 @@
5449
c = 1; # d
5550
}
5651
rec # a
57-
{
58-
# b
52+
{ # b
5953
c = 1;
6054
}
6155
rec # a
62-
{
63-
# b
56+
{ # b
6457
c = 1; # d
6558
}
6659

test/diff/comment/out-pure.nix

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@
103103
```
104104
*/
105105

106-
[
107-
# 1
106+
[ # 1
108107
#2
109108
a # 3
110109
b
@@ -121,8 +120,7 @@
121120
a = 123; # comment
122121
}
123122

124-
{
125-
# 1
123+
{ # 1
126124
#2
127125
a = 1; # 3
128126
b = 1;

test/diff/comment/out.nix

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@
103103
```
104104
*/
105105

106-
[
107-
# 1
106+
[ # 1
108107
#2
109108
a # 3
110109
b
@@ -121,8 +120,7 @@
121120
a = 123; # comment
122121
}
123122

124-
{
125-
# 1
123+
{ # 1
126124
#2
127125
a = 1; # 3
128126
b = 1;

test/diff/idioms_lib_4/out-pure.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,7 @@ rec {
588588
families = { };
589589
};
590590
}
591-
// {
592-
# aliases
591+
// { # aliases
593592
# 'darwin' is the kernel for all of them. We choose macOS by default.
594593
darwin = kernels.macos;
595594
watchos = kernels.ios;

test/diff/idioms_lib_4/out.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,7 @@ rec {
588588
families = { };
589589
};
590590
}
591-
// {
592-
# aliases
591+
// { # aliases
593592
# 'darwin' is the kernel for all of them. We choose macOS by default.
594593
darwin = kernels.macos;
595594
watchos = kernels.ios;

test/diff/idioms_pkgs_4/out-pure.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ in
163163
cc =
164164
let
165165
nativePrefix =
166-
{
167-
# switch
166+
{ # switch
168167
i686-solaris = "/usr/gnu";
169168
x86_64-solaris = "/opt/local/gcc47";
170169
}

test/diff/idioms_pkgs_4/out.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ in
167167
cc =
168168
let
169169
nativePrefix =
170-
{
171-
# switch
170+
{ # switch
172171
i686-solaris = "/usr/gnu";
173172
x86_64-solaris = "/opt/local/gcc47";
174173
}

test/diff/lists/out-pure.nix

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
foo2 = "barbar";
2424
}
2525
]
26-
{
27-
# List in attrset with comment
26+
{ # List in attrset with comment
2827

2928
imports0 = [ ];
3029

@@ -66,23 +65,19 @@
6665
b # c
6766
d # e
6867
]
69-
[
70-
# a
68+
[ # a
7169
b
7270
d
7371
]
74-
[
75-
# a
72+
[ # a
7673
b
7774
d # e
7875
]
79-
[
80-
# a
76+
[ # a
8177
b # c
8278
d
8379
]
84-
[
85-
# a
80+
[ # a
8681
b # c
8782
d # e
8883
]

0 commit comments

Comments
 (0)