Skip to content

Commit

Permalink
Infer line count from file instead of using parser newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
reese authored May 19, 2023
1 parent 21d4362 commit afc9e57
Showing 1 changed file with 1 addition and 7 deletions.
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

0 comments on commit afc9e57

Please sign in to comment.