Skip to content

Commit 909b45a

Browse files
authored
Merge pull request #380 from etiennebarrie/lambda-keyword-block
Always use do/end for multiline lambdas
2 parents 20c62ef + 32d6d8a commit 909b45a

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

Diff for: lib/syntax_tree/node.rb

+7-26
Original file line numberDiff line numberDiff line change
@@ -7210,36 +7210,17 @@ def format(q)
72107210
q.text(" ")
72117211
q
72127212
.if_break do
7213-
force_parens =
7214-
q.parents.any? do |node|
7215-
node.is_a?(Command) || node.is_a?(CommandCall)
7216-
end
7217-
7218-
if force_parens
7219-
q.text("{")
7213+
q.text("do")
72207214

7221-
unless statements.empty?
7222-
q.indent do
7223-
q.breakable_space
7224-
q.format(statements)
7225-
end
7215+
unless statements.empty?
7216+
q.indent do
72267217
q.breakable_space
7218+
q.format(statements)
72277219
end
7228-
7229-
q.text("}")
7230-
else
7231-
q.text("do")
7232-
7233-
unless statements.empty?
7234-
q.indent do
7235-
q.breakable_space
7236-
q.format(statements)
7237-
end
7238-
end
7239-
7240-
q.breakable_space
7241-
q.text("end")
72427220
end
7221+
7222+
q.breakable_space
7223+
q.text("end")
72437224
end
72447225
.if_flat do
72457226
q.text("{")

Diff for: test/fixtures/lambda.rb

+28
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,31 @@
8080
-> do # comment1
8181
# comment2
8282
end
83+
% # multiline lambda in a command
84+
command "arg" do
85+
-> {
86+
multi
87+
line
88+
}
89+
end
90+
-
91+
command "arg" do
92+
-> do
93+
multi
94+
line
95+
end
96+
end
97+
% # multiline lambda in a command call
98+
command.call "arg" do
99+
-> {
100+
multi
101+
line
102+
}
103+
end
104+
-
105+
command.call "arg" do
106+
-> do
107+
multi
108+
line
109+
end
110+
end

0 commit comments

Comments
 (0)