From 862652c2a65b96af873025fc0bc08d4a43fe57c7 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Fri, 21 Jul 2023 14:34:28 -0700 Subject: [PATCH] Revert "Fix comment rendering for sclasses (#420)" (#441) * Revert "Fix comment rendering for sclasses (#420)" This reverts commit 3b06f3c2594571cdfc5f605be69ad74f33fa2637. * Add shellcheck-ignore * Add a test case --- fixtures/small/sclass_actual.rb | 12 +++--------- fixtures/small/sclass_expected.rb | 13 ++++--------- librubyfmt/rubyfmt_lib.rb | 5 ++--- librubyfmt/src/format.rs | 24 +++++++++++++++++++++--- script/docker_release_linux | 1 + 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/fixtures/small/sclass_actual.rb b/fixtures/small/sclass_actual.rb index b3fc4aef..e1fcb0a3 100644 --- a/fixtures/small/sclass_actual.rb +++ b/fixtures/small/sclass_actual.rb @@ -3,17 +3,11 @@ class << self end end -# The moon beams white on the peach blossoms, -# the Milky Way moored silvering at midnight. -class MoonBeam - # I wonder if the nightingale has noticed - # the spring spirit already alive in the branch? +class Bar class << self - # I can hardly get to sleep - # as if tenderness were a sickness. - def show - end end + + def another_method!; end end Foo.machine diff --git a/fixtures/small/sclass_expected.rb b/fixtures/small/sclass_expected.rb index b3fc4aef..3f6bda91 100644 --- a/fixtures/small/sclass_expected.rb +++ b/fixtures/small/sclass_expected.rb @@ -3,16 +3,11 @@ class << self end end -# The moon beams white on the peach blossoms, -# the Milky Way moored silvering at midnight. -class MoonBeam - # I wonder if the nightingale has noticed - # the spring spirit already alive in the branch? +class Bar class << self - # I can hardly get to sleep - # as if tenderness were a sickness. - def show - end + end + + def another_method! end end diff --git a/librubyfmt/rubyfmt_lib.rb b/librubyfmt/rubyfmt_lib.rb index c83f2fd5..385fa1ed 100644 --- a/librubyfmt/rubyfmt_lib.rb +++ b/librubyfmt/rubyfmt_lib.rb @@ -45,7 +45,6 @@ def initialize(file_data) "return" => [], "when" => [], "case" => [], - "class" => [], "yield" => [], "break" => [], "super" => [], @@ -407,11 +406,11 @@ def on_defs(*args) end def on_class(*args) - super + [start_end_for_keyword("class")] + with_lineno { super } end def on_sclass(*args) - super + [start_end_for_keyword("class")] + with_lineno { super } end def on_module(*args) diff --git a/librubyfmt/src/format.rs b/librubyfmt/src/format.rs index 941c020a..51bcf06f 100644 --- a/librubyfmt/src/format.rs +++ b/librubyfmt/src/format.rs @@ -3581,8 +3581,6 @@ pub fn format_sclass(ps: &mut dyn ConcreteParserState, sc: SClass) { let body = sc.2; let end_line = sc.3.end_line(); - ps.on_line(sc.3.start_line()); - ps.with_start_of_line( false, Box::new(|ps| { @@ -3591,9 +3589,29 @@ pub fn format_sclass(ps: &mut dyn ConcreteParserState, sc: SClass) { ps.emit_ident("<<".to_string()); ps.emit_space(); format_expression(ps, *expr); - format_constant_body(ps, body, end_line); + ps.emit_newline(); + ps.new_block(Box::new(|ps| { + ps.with_start_of_line( + true, + Box::new(|ps| { + format_bodystmt(ps, body, end_line); + }), + ); + })); }), ); + ps.with_start_of_line( + true, + Box::new(|ps| { + ps.emit_end(); + }), + ); + + ps.on_line(end_line); + + if ps.at_start_of_line() { + ps.emit_newline(); + } } pub fn format_stabby_lambda(ps: &mut dyn ConcreteParserState, sl: StabbyLambda) { diff --git a/script/docker_release_linux b/script/docker_release_linux index ef048cf0..bb935abd 100755 --- a/script/docker_release_linux +++ b/script/docker_release_linux @@ -22,6 +22,7 @@ for platform in "${platforms[@]}"; do chmod 666 /root/out/* EOF ) > file + # shellcheck disable=SC2086 docker run --platform=$platform --cpus=4 -it -v "$(pwd)/out:/root/out" "rubyfmt-release-linux-$platform:$(git rev-parse HEAD)" bash -c "$(cat file)" mkdir -p "releases/$TAG" cp out/*.tar.gz "releases/$TAG/"