Skip to content
Closed
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
12 changes: 6 additions & 6 deletions fixtures/small/paren_expr_calls_expected.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
a((1))
other_cool_method((a + b).round(4))
a(1)
other_cool_method(a + b.round(4))

# rubocop:disable PrisonGuard/PrivateModule
(foo(
foo(
# rubocop:enable PrisonGuard/PrivateModule
foo
))
)
.flatten

# rubocop:disable Style/Stuff
(MyModel::InSomeNamespace
MyModel::InSomeNamespace
.load_one(
# rubocop:enable Style/Stuff
{name: "name"}
)
&.rules)
&.rules
.freeze

beekeep((the_bees unless not_the_bees!))
23 changes: 20 additions & 3 deletions librubyfmt/src/format_prism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,23 @@
}

fn format_parentheses_node(ps: &mut ParserState, parentheses_node: prism::ParenthesesNode) {
ps.emit_open_paren();
let mut want_parens = true;
if let Some(body) = parentheses_node.body() {

Check failure on line 2897 in librubyfmt/src/format_prism.rs

View workflow job for this annotation

GitHub Actions / clippy

this `if` statement can be collapsed
if let Some(statements_node) = body.as_statements_node() {

Check failure on line 2898 in librubyfmt/src/format_prism.rs

View workflow job for this annotation

GitHub Actions / clippy

this `if` statement can be collapsed
if statements_node.body().len() == 1 {
let the_node = statements_node.body().iter().next().unwrap();
if !(the_node.as_unless_node().is_some() || the_node.as_if_node().is_some()) {
want_parens = false;
}
if the_node.as_range_node().is_some() {
want_parens = true;
}
}
}
}
if want_parens {
ps.emit_open_paren();
}

let is_multiline = if let Some(body) = parentheses_node.body() {
if let Some(statements_node) = body.as_statements_node() {
Expand Down Expand Up @@ -2935,8 +2951,9 @@

if is_multiline {
ps.emit_indent();
ps.emit_close_paren();
} else {
}

if want_parens {
ps.emit_close_paren();
}
}
Expand Down
Loading