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
10 changes: 10 additions & 0 deletions fixtures/small/raise_omitted_hash_value_actual.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def boom(cause)
raise(ArgumentError, "message", cause:)
end

def retry_with(cause)
raise(RetryError, cause:)
cleanup
end

raise(Error, cause:) if cause
10 changes: 10 additions & 0 deletions fixtures/small/raise_omitted_hash_value_expected.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def boom(cause)
raise(ArgumentError, "message", cause:)
end

def retry_with(cause)
raise(RetryError, cause:)
cleanup
end

raise(Error, cause:) if cause
13 changes: 13 additions & 0 deletions librubyfmt/src/format_prism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,19 @@ fn use_parens_for_call_node<'src>(
return true;
}

// Without parens, an omitted value at the end of the arguments
// (`raise Foo, cause:`) would take whatever comes next as its value
if call_node
.arguments()
.and_then(|arguments| arguments.arguments().last())
.and_then(|arg| arg.as_keyword_hash_node())
.and_then(|hash| hash.elements().last())
.and_then(|element| element.as_assoc_node())
.is_some_and(|assoc| assoc.value().as_implicit_node().is_some())
{
return true;
}

if let Some(arguments) = call_node.arguments()
&& arguments.arguments().iter().any(|arg| {
arg.as_splat_node().is_some() || arg.as_forwarding_arguments_node().is_some()
Expand Down
Loading