Skip to content

Commit 081d3af

Browse files
nicholasdowerreese
andauthored
[fix] Handle inline comments after rescue \ (#912)
* [fix] Handle inline comments after `rescue \` * Avoid unwrap Co-authored-by: Reese Williams <reese@reesew.com> * Add comment --------- Co-authored-by: Reese Williams <reese@reesew.com>
1 parent b2a11b6 commit 081d3af

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
begin
2+
rescue Foo # comment
3+
end
4+
5+
begin
6+
rescue Foo,
7+
Bar # comment
8+
end
9+
10+
begin
11+
rescue \
12+
Foo # comment
13+
end
14+
15+
begin
16+
rescue \
17+
Foo,
18+
Bar # comment
19+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
begin
2+
# comment
3+
rescue Foo
4+
end
5+
6+
begin
7+
rescue Foo,
8+
# comment
9+
Bar
10+
end
11+
12+
begin
13+
# comment
14+
rescue Foo
15+
end
16+
17+
begin
18+
rescue Foo,
19+
# comment
20+
Bar
21+
end

librubyfmt/src/format_prism.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,6 +4725,8 @@ fn format_rescue_node<'src>(ps: &mut ParserState<'src>, rescue_node: prism::Resc
47254725
let exceptions = rescue_node.exceptions();
47264726
let reference = rescue_node.reference();
47274727
if !exceptions.is_empty() {
4728+
// Preemptively extract inline comments so they land before rescue, not inside the breakable.
4729+
ps.at_offset(exceptions.first().unwrap().location().start_offset());
47284730
ps.with_start_of_line(false, |ps| {
47294731
ps.inline_breakable_of(BreakableDelims::for_binary_op(), |ps| {
47304732
let exceptions_count = exceptions.len();

0 commit comments

Comments
 (0)