Skip to content

Commit

Permalink
Also apply to params at the end of the line
Browse files Browse the repository at this point in the history
  • Loading branch information
reese authored Feb 21, 2024
1 parent b9827fb commit 88e1c18
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
5 changes: 4 additions & 1 deletion fixtures/small/block_param_line_length_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls.foo.bar.baz.quux.what_comes_after_quux_idk_aaaahhhh.map { |model|
body_of_the_call
}
}

ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls.foo.bar.baz.quux.what_comes_after_quux_idk_aaaahhhhhhh.map(&:foo)
ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls::ThisIsAReallyLongClassName::ButSlightShorter.new(foo: bar_baz_quuz)
10 changes: 10 additions & 0 deletions fixtures/small/block_param_line_length_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@
.map { |model|
body_of_the_call
}

ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls
.foo
.bar
.baz
.quux
.what_comes_after_quux_idk_aaaahhhhhhh
.map(&:foo)
ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls::ThisIsAReallyLongClassName::ButSlightShorter
.new(foo: bar_baz_quuz)
6 changes: 2 additions & 4 deletions fixtures/small/breakables_over_line_length_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
ReallyLongThing
]

if Opus::Foo::Bar::Baz::ReallyLongName::Example::ExampleExampleExampleExampleExampleExampleExampleExample.calls_a_thing(
a,
b
)
if Opus::Foo::Bar::Baz::ReallyLongName::Example::ExampleExampleExampleExampleExampleExampleExampleExample
.calls_a_thing(a, b)
puts("")
end
61 changes: 31 additions & 30 deletions fixtures/small/heredoc_method_call_expected.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
class William::Carlos::Williams
landscape_with_the_fall_of_icarus = T.let(
new(
<<~LANDSCAPE
According to Brueghel
when Icarus fell
it was spring
a farmer was ploughing
his field
the whole pageantry
of the year was
awake tingling
with itself
sweating in the sun
that melted
the wings' wax
unsignificantly
off the coast
there was
a splash quite unnoticed
this was
Icarus drowning
LANDSCAPE
),
Williams
)
landscape_with_the_fall_of_icarus = T
.let(
new(
<<~LANDSCAPE
According to Brueghel
when Icarus fell
it was spring
a farmer was ploughing
his field
the whole pageantry
of the year was
awake tingling
with itself
sweating in the sun
that melted
the wings' wax
unsignificantly
off the coast
there was
a splash quite unnoticed
this was
Icarus drowning
LANDSCAPE
),
Williams
)
end

optp
Expand Down
14 changes: 3 additions & 11 deletions librubyfmt/src/render_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,10 @@ impl AbstractTokenTarget for BreakableCallChainEntry {
{
tokens.pop();
}
// If the last breakable extends beyond the line length but the call chain doesn't,
// the breakable will break itself, e.g.
// ```ruby
// # ↓ if the break is here, we'll break the parens instead of the call chain
// AssumeThisIs.one_hundred_twenty_characters(breaks_here)
// ```
// If the last breakable is multiline (and not a block), ignore it. The user likely
// intentionally chose a line break strategy, so try our best to respect it
if let Some(AbstractLineToken::BreakableEntry(be)) = tokens.last() {
// For block params, always pop it if it's multiline, otherwise we'd *always* multiline the whole block regardless of the contents.
// Never pop brace blocks, since we've already cleared their contents above, so now we're only looking at the params, which are still relevant.
if (be.delims != BreakableDelims::for_block_params() || be.is_multiline())
&& be.delims != BreakableDelims::for_brace_block()
{
if be.is_multiline() && be.delims != BreakableDelims::for_brace_block() {
tokens.pop();
}
}
Expand Down

0 comments on commit 88e1c18

Please sign in to comment.