Skip to content

Commit

Permalink
Revert "Fix comment rendering for sclasses (#420)" (#441)
Browse files Browse the repository at this point in the history
* Revert "Fix comment rendering for sclasses (#420)"

This reverts commit 3b06f3c.

* Add shellcheck-ignore

* Add a test case
  • Loading branch information
reese authored Jul 21, 2023
1 parent 44f7439 commit 862652c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
12 changes: 3 additions & 9 deletions fixtures/small/sclass_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 4 additions & 9 deletions fixtures/small/sclass_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions librubyfmt/rubyfmt_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def initialize(file_data)
"return" => [],
"when" => [],
"case" => [],
"class" => [],
"yield" => [],
"break" => [],
"super" => [],
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 21 additions & 3 deletions librubyfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions script/docker_release_linux
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down

0 comments on commit 862652c

Please sign in to comment.