Skip to content

Commit 828f7cb

Browse files
authored
Merge pull request #91 from ruby-syntax-tree/aryptn
Always use [] with aryptn
2 parents aff3912 + eb264ab commit 828f7cb

File tree

4 files changed

+60
-30
lines changed

4 files changed

+60
-30
lines changed

lib/syntax_tree/node.rb

+7-25
Original file line numberDiff line numberDiff line change
@@ -1123,38 +1123,20 @@ def deconstruct_keys(_keys)
11231123
end
11241124

11251125
def format(q)
1126-
parts = [*requireds]
1127-
parts << RestFormatter.new(rest) if rest
1128-
parts += posts
1129-
1130-
if constant
1131-
q.group do
1132-
q.format(constant)
1133-
q.text("[")
1134-
q.indent do
1135-
q.breakable("")
1136-
q.seplist(parts) { |part| q.format(part) }
1137-
end
1138-
q.breakable("")
1139-
q.text("]")
1140-
end
1141-
1142-
return
1143-
end
1144-
1145-
parent = q.parent
1146-
if parts.length == 1 || PATTERNS.include?(parent.class)
1126+
q.group do
1127+
q.format(constant) if constant
11471128
q.text("[")
11481129
q.indent do
11491130
q.breakable("")
1131+
1132+
parts = [*requireds]
1133+
parts << RestFormatter.new(rest) if rest
1134+
parts += posts
1135+
11501136
q.seplist(parts) { |part| q.format(part) }
11511137
end
11521138
q.breakable("")
11531139
q.text("]")
1154-
elsif parts.empty?
1155-
q.text("[]")
1156-
else
1157-
q.group { q.seplist(parts) { |part| q.format(part) } }
11581140
end
11591141
end
11601142
end

test/fixtures/aryptn.rb

+44-3
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,92 @@
66
case foo
77
in _, _
88
end
9+
-
10+
case foo
11+
in [_, _]
12+
end
913
%
1014
case foo
1115
in bar, baz
1216
end
17+
-
18+
case foo
19+
in [bar, baz]
20+
end
1321
%
1422
case foo
1523
in [bar]
1624
end
1725
%
1826
case foo
19-
in [bar, baz]
27+
in [bar]
28+
in [baz]
2029
end
21-
-
30+
%
2231
case foo
23-
in bar, baz
32+
in [bar, baz]
2433
end
2534
%
2635
case foo
2736
in bar, *baz
2837
end
38+
-
39+
case foo
40+
in [bar, *baz]
41+
end
2942
%
3043
case foo
3144
in *bar, baz
3245
end
46+
-
47+
case foo
48+
in [*bar, baz]
49+
end
3350
%
3451
case foo
3552
in bar, *, baz
3653
end
54+
-
55+
case foo
56+
in [bar, *, baz]
57+
end
3758
%
3859
case foo
3960
in *, bar, baz
4061
end
62+
-
63+
case foo
64+
in [*, bar, baz]
65+
end
4166
%
4267
case foo
4368
in Constant[bar]
4469
end
4570
%
4671
case foo
72+
in Constant(bar)
73+
end
74+
-
75+
case foo
76+
in Constant[bar]
77+
end
78+
%
79+
case foo
4780
in Constant[bar, baz]
4881
end
4982
%
5083
case foo
5184
in bar, [baz, _] => qux
5285
end
86+
-
87+
case foo
88+
in [bar, [baz, _] => qux]
89+
end
5390
%
5491
case foo
5592
in bar, baz if bar == baz
5693
end
94+
-
95+
case foo
96+
in [bar, baz] if bar == baz
97+
end

test/fixtures/hshptn.rb

+5
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@
7171
in bar, { baz:, **nil }
7272
in qux:
7373
end
74+
-
75+
case foo
76+
in [bar, { baz:, **nil }]
77+
in qux:
78+
end

test/fixtures/in.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
end
1515
-
1616
case foo
17-
in fooooooooooooooooooooooooooooooooooooo,
18-
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
17+
in [
18+
fooooooooooooooooooooooooooooooooooooo,
19+
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
20+
]
1921
baz
2022
end
2123
%

0 commit comments

Comments
 (0)