Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions fixtures/small/rescue_inline_comment_actual.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
begin
rescue Foo # comment
end

begin
rescue Foo,
Bar # comment
end

begin
rescue \
Foo # comment
end

begin
rescue \
Foo,
Bar # comment
end
21 changes: 21 additions & 0 deletions fixtures/small/rescue_inline_comment_expected.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
begin
# comment
rescue Foo
end

begin
rescue Foo,
# comment
Bar
end

begin
# comment
rescue Foo
end

begin
rescue Foo,
# comment
Bar
end
2 changes: 2 additions & 0 deletions librubyfmt/src/format_prism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4728,6 +4728,8 @@ fn format_rescue_node<'src>(ps: &mut ParserState<'src>, rescue_node: prism::Resc
let exceptions = rescue_node.exceptions();
let reference = rescue_node.reference();
if !exceptions.is_empty() {
// Preemptively extract inline comments so they land before rescue, not inside the breakable.
ps.at_offset(exceptions.first().unwrap().location().start_offset());
ps.with_start_of_line(false, |ps| {
ps.inline_breakable_of(BreakableDelims::for_binary_op(), |ps| {
let exceptions_count = exceptions.len();
Expand Down