Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix winding lines forward multiple lines #429

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fixtures/small/all_method_blocks_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@
a.b 1 do

end

a do
# Comment at the beginning


# Comment at the end
end
7 changes: 7 additions & 0 deletions fixtures/small/all_method_blocks_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@

a.b(1) do
end

a do
# Comment at the beginning


# Comment at the end
end
11 changes: 11 additions & 0 deletions fixtures/small/begin_ensure_rescue_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ def func_with_comments
end
end

def another_func_with_comments
begin
# We don't do anything in here

# for some good reason
rescue
# I promise it's a good reason

end
end

def func_with_mulilines
_lambda_to_break_stuff = lambda do |this, that, the_other|
wreak_havoc!
Expand Down
11 changes: 11 additions & 0 deletions fixtures/small/begin_ensure_rescue_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def func_with_comments
end
end

def another_func_with_comments
begin
# We don't do anything in here

# for some good reason
rescue
# I promise it's a good reason

end
end

def func_with_mulilines
_lambda_to_break_stuff = lambda do |this, that, the_other|
wreak_havoc!
Expand Down
8 changes: 1 addition & 7 deletions librubyfmt/rubyfmt_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,10 @@ def initialize(file_data)
@rbracket_stack = []
@lbrace_stack = []
@comments = {}
@last_ln = 0
# binary contents comming after a `__END__` node
@data_contents_start_line = nil
end

def on_nl(*args)
@last_ln = lineno+1
super(*args)
end

# This method has incorrect behavior inside Ripper,
# so we patch it for now
# original: https://github.com/ruby/ruby/blob/118368c1dd9304c0c21a4437016af235bd9b8438/ext/ripper/lib/ripper/sexp.rb#L144-L155
Expand Down Expand Up @@ -113,7 +107,7 @@ def parse
nil
end

[res, @comments, @lines_with_any_ruby, @last_ln, data_contents]
[res, @comments, @lines_with_any_ruby, @file_lines.count, data_contents]
end
end

Expand Down