From ada3c39c75157be264329ed1ccf8b2cff533c6f5 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 05:55:21 +0000 Subject: [PATCH 01/10] Fixtures --- fixtures/small/block_param_line_length_actual.rb | 7 +++++++ fixtures/small/block_param_line_length_expected.rb | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 fixtures/small/block_param_line_length_actual.rb create mode 100644 fixtures/small/block_param_line_length_expected.rb diff --git a/fixtures/small/block_param_line_length_actual.rb b/fixtures/small/block_param_line_length_actual.rb new file mode 100644 index 00000000..eea45f93 --- /dev/null +++ b/fixtures/small/block_param_line_length_actual.rb @@ -0,0 +1,7 @@ +ThisIsAReallyLongClassName::WithSomeModulesInsideItThatHaveAMethodThatWeWillCallRightAroundHereeeee.do_stuff(boom) do |foo| + some_stuff! +end + +ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls.foo.bar.baz.quux.what_comes_after_quux_idk_aaaahhhh.map { |model| + body_of_the_call +} \ No newline at end of file diff --git a/fixtures/small/block_param_line_length_expected.rb b/fixtures/small/block_param_line_length_expected.rb new file mode 100644 index 00000000..52b1a148 --- /dev/null +++ b/fixtures/small/block_param_line_length_expected.rb @@ -0,0 +1,14 @@ +ThisIsAReallyLongClassName::WithSomeModulesInsideItThatHaveAMethodThatWeWillCallRightAroundHereeeee + .do_stuff(boom) do |foo| + some_stuff! + end + +ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls + .foo + .bar + .baz + .quux + .what_comes_after_quux_idk_aaaahhhh + .map { |model| + body_of_the_call + } From 378b98aca36889f84960699833aa5101431813d1 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 05:55:55 +0000 Subject: [PATCH 02/10] Keep block params intact when checking line length of call chains --- librubyfmt/src/delimiters.rs | 4 ++-- librubyfmt/src/render_targets.rs | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/librubyfmt/src/delimiters.rs b/librubyfmt/src/delimiters.rs index 08317dc4..50959713 100644 --- a/librubyfmt/src/delimiters.rs +++ b/librubyfmt/src/delimiters.rs @@ -1,6 +1,6 @@ use crate::line_tokens::ConcreteLineToken; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Eq, PartialEq)] struct DelimiterPair { open: String, close: String, @@ -12,7 +12,7 @@ impl DelimiterPair { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct BreakableDelims { single_line: DelimiterPair, multi_line: DelimiterPair, diff --git a/librubyfmt/src/render_targets.rs b/librubyfmt/src/render_targets.rs index f17e71c0..acae4ab0 100644 --- a/librubyfmt/src/render_targets.rs +++ b/librubyfmt/src/render_targets.rs @@ -252,37 +252,51 @@ impl AbstractTokenTarget for BreakableCallChainEntry { // individual line and get _that_ max length. let mut tokens = self.tokens.clone(); if tokens.len() > 2 { - if let Some(AbstractLineToken::ConcreteLineToken(ConcreteLineToken::End)) = - tokens.get(tokens.len() - 2) - { - // Pop off all tokens that make up the `do`/`end` block (but not `do`!), + let index = tokens.len() - 2; + let token = tokens.get_mut(index).unwrap(); + if matches!(token, AbstractLineToken::ConcreteLineToken(ConcreteLineToken::End)) { + // Pop off all tokens that make up the block (but not the block params!), // since we assume that the block contents will handle their own line // length appropriately. while let Some(token) = tokens.last() { if matches!( token, - AbstractLineToken::ConcreteLineToken(ConcreteLineToken::DoKeyword) + AbstractLineToken::BreakableEntry(BreakableEntry { delims, .. }) if *delims == BreakableDelims::for_block_params() ) { break; } tokens.pop(); } + } else if let AbstractLineToken::BreakableEntry(BreakableEntry { delims, ref mut tokens, .. }) = token { + if *delims == BreakableDelims::for_brace_block() { + if let Some(AbstractLineToken::BreakableEntry(BreakableEntry { delims, .. })) = tokens.first() { + if *delims == BreakableDelims::for_block_params() { + // Wipe away the body of the block and leave only the params + *tokens= vec![tokens.first().unwrap().clone()]; + } + } + } } } if let Some(AbstractLineToken::BreakableEntry(_)) = tokens.first() { tokens.remove(0); } - // EndCallChainIndent, which we don't care about - tokens.pop(); + if let Some(AbstractLineToken::ConcreteLineToken(ConcreteLineToken::EndCallChainIndent)) = tokens.last() { + 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 let Some(AbstractLineToken::BreakableEntry(_)) = tokens.last() { - tokens.pop(); + 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() { + tokens.pop(); + } } tokens.insert( 0, From b9827fb6ad086a4c2b6536247fe6c22325ac4925 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 05:58:54 +0000 Subject: [PATCH 03/10] fmt --- librubyfmt/src/render_targets.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/librubyfmt/src/render_targets.rs b/librubyfmt/src/render_targets.rs index acae4ab0..c110103e 100644 --- a/librubyfmt/src/render_targets.rs +++ b/librubyfmt/src/render_targets.rs @@ -254,7 +254,10 @@ impl AbstractTokenTarget for BreakableCallChainEntry { if tokens.len() > 2 { let index = tokens.len() - 2; let token = tokens.get_mut(index).unwrap(); - if matches!(token, AbstractLineToken::ConcreteLineToken(ConcreteLineToken::End)) { + if matches!( + token, + AbstractLineToken::ConcreteLineToken(ConcreteLineToken::End) + ) { // Pop off all tokens that make up the block (but not the block params!), // since we assume that the block contents will handle their own line // length appropriately. @@ -267,12 +270,20 @@ impl AbstractTokenTarget for BreakableCallChainEntry { } tokens.pop(); } - } else if let AbstractLineToken::BreakableEntry(BreakableEntry { delims, ref mut tokens, .. }) = token { + } else if let AbstractLineToken::BreakableEntry(BreakableEntry { + delims, + ref mut tokens, + .. + }) = token + { if *delims == BreakableDelims::for_brace_block() { - if let Some(AbstractLineToken::BreakableEntry(BreakableEntry { delims, .. })) = tokens.first() { + if let Some(AbstractLineToken::BreakableEntry(BreakableEntry { + delims, .. + })) = tokens.first() + { if *delims == BreakableDelims::for_block_params() { // Wipe away the body of the block and leave only the params - *tokens= vec![tokens.first().unwrap().clone()]; + *tokens = vec![tokens.first().unwrap().clone()]; } } } @@ -282,7 +293,9 @@ impl AbstractTokenTarget for BreakableCallChainEntry { if let Some(AbstractLineToken::BreakableEntry(_)) = tokens.first() { tokens.remove(0); } - if let Some(AbstractLineToken::ConcreteLineToken(ConcreteLineToken::EndCallChainIndent)) = tokens.last() { + if let Some(AbstractLineToken::ConcreteLineToken(ConcreteLineToken::EndCallChainIndent)) = + tokens.last() + { tokens.pop(); } // If the last breakable extends beyond the line length but the call chain doesn't, @@ -294,7 +307,9 @@ impl AbstractTokenTarget for BreakableCallChainEntry { 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.delims != BreakableDelims::for_block_params() || be.is_multiline()) + && be.delims != BreakableDelims::for_brace_block() + { tokens.pop(); } } From 01987e33d4a3ae9b080659406ec29140172a68cf Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 18:03:16 +0000 Subject: [PATCH 04/10] Also apply to params at the end of the line --- .../small/block_param_line_length_actual.rb | 5 +- .../small/block_param_line_length_expected.rb | 10 +++ .../breakables_over_line_length_expected.rb | 6 +- .../small/heredoc_method_call_expected.rb | 61 ++++++++++--------- librubyfmt/src/render_targets.rs | 20 +++--- 5 files changed, 56 insertions(+), 46 deletions(-) diff --git a/fixtures/small/block_param_line_length_actual.rb b/fixtures/small/block_param_line_length_actual.rb index eea45f93..4f87e0fa 100644 --- a/fixtures/small/block_param_line_length_actual.rb +++ b/fixtures/small/block_param_line_length_actual.rb @@ -4,4 +4,7 @@ ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls.foo.bar.baz.quux.what_comes_after_quux_idk_aaaahhhh.map { |model| body_of_the_call -} \ No newline at end of file +} + +ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls.foo.bar.baz.quux.what_comes_after_quux_idk_aaaahhhhhhh.map(&:foo) +ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls::ThisIsAReallyLongClassName::ButSlightShorter.new(foo: bar_baz_quuz) \ No newline at end of file diff --git a/fixtures/small/block_param_line_length_expected.rb b/fixtures/small/block_param_line_length_expected.rb index 52b1a148..535a5a6e 100644 --- a/fixtures/small/block_param_line_length_expected.rb +++ b/fixtures/small/block_param_line_length_expected.rb @@ -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) diff --git a/fixtures/small/breakables_over_line_length_expected.rb b/fixtures/small/breakables_over_line_length_expected.rb index 6d4da475..79b4d17a 100644 --- a/fixtures/small/breakables_over_line_length_expected.rb +++ b/fixtures/small/breakables_over_line_length_expected.rb @@ -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 diff --git a/fixtures/small/heredoc_method_call_expected.rb b/fixtures/small/heredoc_method_call_expected.rb index 903e4ff9..324347ea 100644 --- a/fixtures/small/heredoc_method_call_expected.rb +++ b/fixtures/small/heredoc_method_call_expected.rb @@ -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 diff --git a/librubyfmt/src/render_targets.rs b/librubyfmt/src/render_targets.rs index c110103e..c95233a5 100644 --- a/librubyfmt/src/render_targets.rs +++ b/librubyfmt/src/render_targets.rs @@ -284,7 +284,13 @@ impl AbstractTokenTarget for BreakableCallChainEntry { if *delims == BreakableDelims::for_block_params() { // Wipe away the body of the block and leave only the params *tokens = vec![tokens.first().unwrap().clone()]; + } else { + // No params, so wipe away the whole thing + *tokens = Vec::new(); } + } else { + // No params, so wipe away the whole thing + *tokens = Vec::new(); } } } @@ -298,18 +304,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(); } } From 3afdd1c769a84b1017bbd4a02fef0dbd1d7033ab Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 19:46:27 +0000 Subject: [PATCH 05/10] Remove my hack --- .github/workflows/preview-release.yaml | 13 +++---------- script/make_release | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/preview-release.yaml b/.github/workflows/preview-release.yaml index 3eaa5b19..6db59f79 100644 --- a/.github/workflows/preview-release.yaml +++ b/.github/workflows/preview-release.yaml @@ -6,7 +6,7 @@ on: - completed push: # Run only on trunk pushes that aren't a new tag release - branches: [trunk] + branches: [trunk, fix-aarch-builds] tags-ignore: "*" env: @@ -64,16 +64,13 @@ jobs: override: true profile: minimal target: aarch64-unknown-linux-gnu - - uses: actions/cache@v2 - with: - path: | - librubyfmt/ruby_checkout - key: ${{ runner.os }}-${{matrix.target}}-ruby-v1-${{ hashFiles('.git/modules/librubyfmt/ruby_checkout/HEAD') }} - if: runner.os == 'macOS' run: | brew install automake bison echo "/usr/local/opt/bison/bin:$PATH" >> $GITHUB_PATH - run: ./script/make_release + env: + TARGET: ${{ matrix.target }} - uses: actions/upload-artifact@v3 with: name: rubyfmt-release-artifact-${{ matrix.os }}-${{ matrix.target }} @@ -109,10 +106,6 @@ jobs: - uses: actions/download-artifact@v3 with: name: rubyfmt-release-artifact-ubuntu-20.04-aarch64-unknown-linux-gnu - - run: | - # The arch part of this path is set with uname, but we cross-compile the arm build on - # an x86 machine, so we want to make sure the name is correct for the release - mv rubyfmt-${{ steps.get-latest-tag.outputs.tag }}-Linux-x86_64.tar.gz rubyfmt-${{ steps.get-latest-tag.outputs.tag }}-Linux-aarch64.tar.gz - uses: actions/download-artifact@v3 with: name: rubyfmt-release-artifact-ubuntu-20.04-native diff --git a/script/make_release b/script/make_release index 9234bfb7..2ac41ef8 100755 --- a/script/make_release +++ b/script/make_release @@ -44,7 +44,7 @@ case "$target" in TARGET_AR=aarch64-linux-gnu-ar \ cargo build --release --target aarch64-unknown-linux-gnu - cargo_target_dir_prefix="aarch64-unknown-linux-gnu" + cargo_target_dir_prefix="aarch64-unknown-linux-gnu/" # This is kind of a hack, since we're assuming we're on a Linux host. release_tarball_os="Linux" release_tarball_arch="aarch64" From d081012786b1ff5324e637ec3e8f52f75d8a3ac5 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 21:11:16 +0000 Subject: [PATCH 06/10] Un-hack prerelease builds --- .github/workflows/preview-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-release.yaml b/.github/workflows/preview-release.yaml index 6db59f79..33727aa2 100644 --- a/.github/workflows/preview-release.yaml +++ b/.github/workflows/preview-release.yaml @@ -6,7 +6,7 @@ on: - completed push: # Run only on trunk pushes that aren't a new tag release - branches: [trunk, fix-aarch-builds] + branches: [trunk] tags-ignore: "*" env: From 86da1278224584e9c1f965210f072317c83b2659 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 21:48:05 +0000 Subject: [PATCH 07/10] boop From b72b7579f171128778d14ba0f82658097256a5ed Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Wed, 21 Feb 2024 21:51:38 +0000 Subject: [PATCH 08/10] hack --- .github/workflows/preview-release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-release.yaml b/.github/workflows/preview-release.yaml index 33727aa2..7c7f1498 100644 --- a/.github/workflows/preview-release.yaml +++ b/.github/workflows/preview-release.yaml @@ -6,7 +6,7 @@ on: - completed push: # Run only on trunk pushes that aren't a new tag release - branches: [trunk] + branches: [trunk, reese-hack-special-release] tags-ignore: "*" env: @@ -30,7 +30,7 @@ jobs: level: prepatch - uses: actions-ecosystem/action-push-tag@v1 with: - tag: ${{ steps.bump-semver.outputs.new_version }} + tag: v0.10.18-0 build: runs-on: ${{ matrix.os }} needs: [bump-tag] From 28c633102b27ceff360ea6534926a8019dfeee79 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Thu, 22 Feb 2024 00:28:00 +0000 Subject: [PATCH 09/10] Try and make single-call breakables less ocassionally-gross --- .../small/block_param_line_length_expected.rb | 5 +- .../breakables_over_line_length_expected.rb | 6 +- .../small/heredoc_method_call_expected.rb | 61 +++++++++---------- fixtures/small/long_blockvar_expected.rb | 25 ++++---- .../small/multiline_chain_in_block_actual.rb | 5 ++ .../multiline_chain_in_block_expected.rb | 10 +++ librubyfmt/src/render_targets.rs | 10 ++- 7 files changed, 72 insertions(+), 50 deletions(-) diff --git a/fixtures/small/block_param_line_length_expected.rb b/fixtures/small/block_param_line_length_expected.rb index 535a5a6e..4abaa75c 100644 --- a/fixtures/small/block_param_line_length_expected.rb +++ b/fixtures/small/block_param_line_length_expected.rb @@ -20,5 +20,6 @@ .quux .what_comes_after_quux_idk_aaaahhhhhhh .map(&:foo) -ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls::ThisIsAReallyLongClassName::ButSlightShorter - .new(foo: bar_baz_quuz) +ThisIsAReallyLongClassName::ButSlightShorterWithMoreCalls::ThisIsAReallyLongClassName::ButSlightShorter.new( + foo: bar_baz_quuz +) diff --git a/fixtures/small/breakables_over_line_length_expected.rb b/fixtures/small/breakables_over_line_length_expected.rb index 79b4d17a..6d4da475 100644 --- a/fixtures/small/breakables_over_line_length_expected.rb +++ b/fixtures/small/breakables_over_line_length_expected.rb @@ -18,7 +18,9 @@ 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 diff --git a/fixtures/small/heredoc_method_call_expected.rb b/fixtures/small/heredoc_method_call_expected.rb index 324347ea..903e4ff9 100644 --- a/fixtures/small/heredoc_method_call_expected.rb +++ b/fixtures/small/heredoc_method_call_expected.rb @@ -1,35 +1,34 @@ 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 diff --git a/fixtures/small/long_blockvar_expected.rb b/fixtures/small/long_blockvar_expected.rb index d85153de..11f86030 100644 --- a/fixtures/small/long_blockvar_expected.rb +++ b/fixtures/small/long_blockvar_expected.rb @@ -1,12 +1,13 @@ -things.each do | - omg:, - really:, - dang:, - long:, - blockvar:, - that_is_so_long_if_you_write_this:, - you_should_refactor:, - like_really_this_is_so_long: - | - do_things! -end +things + .each do | + omg:, + really:, + dang:, + long:, + blockvar:, + that_is_so_long_if_you_write_this:, + you_should_refactor:, + like_really_this_is_so_long: + | + do_things! + end diff --git a/fixtures/small/multiline_chain_in_block_actual.rb b/fixtures/small/multiline_chain_in_block_actual.rb index 95bee5bd..5c6fdc0e 100644 --- a/fixtures/small/multiline_chain_in_block_actual.rb +++ b/fixtures/small/multiline_chain_in_block_actual.rb @@ -6,3 +6,8 @@ def ajax_get(route) super end + +class Foo + sig {override.returns(T::Array[T.class_of(Some::Really::Long::Name::ThatshouldprobablybealisedbutisntbecauseThis::IsATestStub)])} + def example = begin; end +end diff --git a/fixtures/small/multiline_chain_in_block_expected.rb b/fixtures/small/multiline_chain_in_block_expected.rb index 7303c03d..2211b250 100644 --- a/fixtures/small/multiline_chain_in_block_expected.rb +++ b/fixtures/small/multiline_chain_in_block_expected.rb @@ -7,3 +7,13 @@ def ajax_get(route) super end + +class Foo + sig { + override.returns( + T::Array[T.class_of(Some::Really::Long::Name::ThatshouldprobablybealisedbutisntbecauseThis::IsATestStub)] + ) + } + def example = begin + end +end diff --git a/librubyfmt/src/render_targets.rs b/librubyfmt/src/render_targets.rs index c95233a5..d02125a1 100644 --- a/librubyfmt/src/render_targets.rs +++ b/librubyfmt/src/render_targets.rs @@ -304,10 +304,14 @@ impl AbstractTokenTarget for BreakableCallChainEntry { { tokens.pop(); } - // 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 + 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 be.is_multiline() && be.delims != BreakableDelims::for_brace_block() { + if (call_count == 1 || be.is_multiline()) && be.delims != BreakableDelims::for_brace_block() && be.delims != BreakableDelims::for_block_params() { tokens.pop(); } } From 166b1d33c815befa74ef4ab20e5a013235115581 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Thu, 22 Feb 2024 00:28:21 +0000 Subject: [PATCH 10/10] boop --- .github/workflows/preview-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-release.yaml b/.github/workflows/preview-release.yaml index 7c7f1498..c417acc9 100644 --- a/.github/workflows/preview-release.yaml +++ b/.github/workflows/preview-release.yaml @@ -30,7 +30,7 @@ jobs: level: prepatch - uses: actions-ecosystem/action-push-tag@v1 with: - tag: v0.10.18-0 + tag: v0.10.19-0 build: runs-on: ${{ matrix.os }} needs: [bump-tag]