Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
reese authored Feb 22, 2024
1 parent 3137316 commit a52a371
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions librubyfmt/src/render_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,27 @@ impl AbstractTokenTarget for BreakableCallChainEntry {
{
tokens.pop();
}
let call_count = tokens.iter().filter(|t| matches!(t, AbstractLineToken::ConcreteLineToken(ConcreteLineToken::Dot | ConcreteLineToken::LonelyOperator))).count();
let call_count = tokens
.iter()
.filter(|t| {
matches!(
t,
AbstractLineToken::ConcreteLineToken(
ConcreteLineToken::Dot | ConcreteLineToken::LonelyOperator
)
)
})
.count();
// If the last breakable is multiline (and not a block/block params), ignore it. The user likely
// intentionally chose a line break strategy, so try our best to respect it.
//
// However, if there's only one item in the chain, try our best to leave that in place.
// `foo\n.bar` is always a little awkward.
if let Some(AbstractLineToken::BreakableEntry(be)) = tokens.last() {
if (call_count == 1 || be.is_multiline()) && be.delims != BreakableDelims::for_brace_block() && be.delims != BreakableDelims::for_block_params() {
if (call_count == 1 || be.is_multiline())
&& be.delims != BreakableDelims::for_brace_block()
&& be.delims != BreakableDelims::for_block_params()
{
tokens.pop();
}
}
Expand Down

0 comments on commit a52a371

Please sign in to comment.