Skip to content

Expand single-letter variable names for better readability #1313

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ def self.alias_extension(old_ext, new_ext)
def self.binary?(file)
return false if file =~ /\.(rdoc|txt)$/

s = File.read(file, 1024) or return false
string = File.read(file, 1024) or return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head or something may be better.


return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
return true if string[0, 2] == Marshal.dump('')[0, 2] or string.index("\x00")

mode = 'r:utf-8' # default source encoding has been changed to utf-8
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
string.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = string[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
mode = "rb:#{encoding}" if encoding
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
string = File.open(file, mode) {|f| f.gets(nil, 1024)}

not s.valid_encoding?
!string.valid_encoding?
end

##
Expand Down
70 changes: 35 additions & 35 deletions lib/rdoc/parser/prism_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ def handle_meta_method_comment(comment, node)

if attributes
attributes.each do |attr|
a = RDoc::Attr.new(@container, attr, rw, processed_comment, singleton: @singleton)
Comment on lines 291 to -292
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attributes.each do |name|
  attr = RDoc::Attr.new(@container, name, ...)

or

attributes.each do |attr_name|
  attr = RDoc::Attr.new(@container, attr_name, ...)

may be better.

a.store = @store
a.line = line_no
record_location(a)
@container.add_attribute(a)
a.visibility = visibility
attr_obj = RDoc::Attr.new(@container, attr, rw, processed_comment, singleton: @singleton)
attr_obj.store = @store
attr_obj.line = line_no
record_location(attr_obj)
@container.add_attribute(attr_obj)
attr_obj.visibility = visibility
end
elsif line_no || node
method_name ||= call_node_name_arguments(node).first if is_call_node
Expand Down Expand Up @@ -401,13 +401,13 @@ def visible_tokens_from_location(location)

def change_method_visibility(names, visibility, singleton: @singleton)
new_methods = []
@container.methods_matching(names, singleton) do |m|
if m.parent != @container
m = m.dup
record_location(m)
new_methods << m
@container.methods_matching(names, singleton) do |method|
if method.parent != @container
method = method.dup
record_location(method)
new_methods << method
else
m.visibility = visibility
method.visibility = visibility
end
end
new_methods.each do |method|
Expand Down Expand Up @@ -449,13 +449,13 @@ def add_alias_method(old_name, new_name, line_no)
comment = consecutive_comment(line_no)
handle_consecutive_comment_directive(@container, comment)
visibility = @container.find_method(old_name, @singleton)&.visibility || :public
a = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton)
handle_modifier_directive(a, line_no)
a.store = @store
a.line = line_no
record_location(a)
if should_document?(a)
@container.add_alias(a)
alias_obj = RDoc::Alias.new(nil, old_name, new_name, comment, singleton: @singleton)
handle_modifier_directive(alias_obj, line_no)
alias_obj.store = @store
alias_obj.line = line_no
record_location(alias_obj)
if should_document?(alias_obj)
@container.add_alias(alias_obj)
@container.find_method(new_name, @singleton)&.visibility = visibility
end
end
Expand All @@ -468,13 +468,13 @@ def add_attributes(names, rw, line_no)
return unless @container.document_children

names.each do |symbol|
a = RDoc::Attr.new(nil, symbol.to_s, rw, comment, singleton: @singleton)
a.store = @store
a.line = line_no
record_location(a)
handle_modifier_directive(a, line_no)
@container.add_attribute(a) if should_document?(a)
a.visibility = visibility # should set after adding to container
attr_obj = RDoc::Attr.new(nil, symbol.to_s, rw, comment, singleton: @singleton)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attr may be better.

attr_obj.store = @store
attr_obj.line = line_no
record_location(attr_obj)
handle_modifier_directive(attr_obj, line_no)
@container.add_attribute(attr_obj) if should_document?(attr_obj)
attr_obj.visibility = visibility # should set after adding to container
end
end

Expand All @@ -483,11 +483,11 @@ def add_includes_extends(names, rdoc_class, line_no) # :nodoc:
comment = consecutive_comment(line_no)
handle_consecutive_comment_directive(@container, comment)
names.each do |name|
ie = @container.add(rdoc_class, name, '')
ie.store = @store
ie.line = line_no
ie.comment = comment
record_location(ie)
include_extend_obj = @container.add(rdoc_class, name, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to remote _obj suffix here.

include_extend_obj.store = @store
include_extend_obj.line = line_no
include_extend_obj.comment = comment
record_location(include_extend_obj)
end
end

Expand Down Expand Up @@ -652,10 +652,10 @@ def add_constant(constant_name, rhs_name, start_line, end_line)
@container.find_module_named(rhs_name)
end
if mod && constant.document_self
a = @container.add_module_alias(mod, rhs_name, constant, @top_level)
a.store = @store
a.line = start_line
record_location(a)
module_alias = @container.add_module_alias(mod, rhs_name, constant, @top_level)
module_alias.store = @store
module_alias.line = start_line
record_location(module_alias)
end
end

Expand Down
24 changes: 12 additions & 12 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ def get_class_or_module container, ignore_constants = false
container = container.find_module_named name_t[:text]
container ||=
if ignore_constants then
c = RDoc::NormalModule.new name_t[:text]
c.store = @store
new_modules << [prev_container, c]
c
module_obj = RDoc::NormalModule.new name_t[:text]
module_obj.store = @store
new_modules << [prev_container, module_obj]
module_obj
else
c = prev_container.add_module RDoc::NormalModule, name_t[:text]
c.ignore unless prev_container.document_children
@top_level.add_to_classes_or_modules c
c
module_obj = prev_container.add_module RDoc::NormalModule, name_t[:text]
module_obj.ignore unless prev_container.document_children
@top_level.add_to_classes_or_modules module_obj
module_obj
end

record_location container
Expand Down Expand Up @@ -700,10 +700,10 @@ def make_message message
# Creates a comment with the correct format

def new_comment comment, line_no = nil
c = RDoc::Comment.new comment, @top_level, :ruby
c.line = line_no
c.format = @markup
c
comment_obj = RDoc::Comment.new comment, @top_level, :ruby
comment_obj.line = line_no
comment_obj.format = @markup
comment_obj
end

##
Expand Down
6 changes: 3 additions & 3 deletions lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,9 @@ def complete_method name, klass, selector, completions # :nodoc:

def display document
page do |io|
f = formatter(io)
f.width = @width if @width and f.respond_to?(:width)
text = document.accept f
formatter = formatter(io)
formatter.width = @width if @width and formatter.respond_to?(:width)
text = document.accept formatter

io.write text
end
Expand Down
Loading