Skip to content

Remove dead or unnecessary methods/attributes #1315

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

Merged
merged 10 commits into from
Mar 16, 2025
28 changes: 0 additions & 28 deletions lib/rdoc/code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ class RDoc::CodeObject

attr_reader :store

##
# We are the model of the code, but we know that at some point we will be
# worked on by viewers. By implementing the Viewable protocol, viewers can
# associated themselves with these objects.

attr_accessor :viewer

##
# When mixed-in to a class, this points to the Context in which it was originally defined.

Expand Down Expand Up @@ -217,20 +210,6 @@ def done_documenting=(value)
@document_children = @document_self
end

##
# Yields each parent of this CodeObject. See also
# RDoc::ClassModule#each_ancestor

def each_parent
code_object = self

while code_object = code_object.parent do
yield code_object
end

self
end

##
# File name where this CodeObject was found.
#
Expand Down Expand Up @@ -327,13 +306,6 @@ def parent
end
end

##
# File name of our parent

def parent_file_name
@parent ? @parent.base_name : '(unknown)'
end

##
# Name of our parent

Expand Down
7 changes: 0 additions & 7 deletions lib/rdoc/code_object/alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ def aref
"#alias-#{type}-#{html_name}"
end

##
# Full old name including namespace

def full_old_name
@full_name || "#{parent.name}#{pretty_old_name}"
end

##
# HTML id-friendly version of +#new_name+.

Expand Down
4 changes: 0 additions & 4 deletions lib/rdoc/code_object/class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class RDoc::ClassModule < RDoc::Context

attr_accessor :comment_location

attr_accessor :diagram # :nodoc:

##
# Class or module this constant is an alias for

Expand All @@ -56,7 +54,6 @@ def self.from_module class_type, mod

klass.parent = mod.parent
klass.section = mod.section
klass.viewer = mod.viewer

klass.attributes.concat mod.attributes
klass.method_list.concat mod.method_list
Expand Down Expand Up @@ -110,7 +107,6 @@ def self.from_module class_type, mod

def initialize(name, superclass = nil)
@constant_aliases = []
@diagram = nil
@is_alias_for = nil
@name = name
@superclass = superclass
Expand Down
44 changes: 1 addition & 43 deletions lib/rdoc/code_object/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,6 @@ def current_section
section
end

##
# Is part of this thing was defined in +file+?

def defined_in?(file)
@in_files.include?(file)
end

def display(method_attr) # :nodoc:
if method_attr.is_a? RDoc::Attr
"#{method_attr.definition} #{method_attr.pretty_name}"
Expand All @@ -713,41 +706,13 @@ def display(method_attr) # :nodoc:
def each_ancestor(&_) # :nodoc:
end

##
# Iterator for attributes

def each_attribute # :yields: attribute
@attributes.each { |a| yield a }
end

##
# Iterator for classes and modules

def each_classmodule(&block) # :yields: module
classes_and_modules.sort.each(&block)
end

##
# Iterator for constants

def each_constant # :yields: constant
@constants.each {|c| yield c}
end

##
# Iterator for included modules

def each_include # :yields: include
@includes.each do |i| yield i end
end

##
# Iterator for extension modules

def each_extend # :yields: extend
@extends.each do |e| yield e end
end

##
# Iterator for methods

Expand Down Expand Up @@ -847,13 +812,6 @@ def find_external_alias_named(name)
end
end

##
# Finds a file with +name+ in this context

def find_file_named name
@store.find_file_named name
end

##
# Finds an instance method with +name+ in this context

Expand All @@ -871,7 +829,7 @@ def find_local_symbol(symbol)
find_attribute_named(symbol) or
find_external_alias_named(symbol) or
find_module_named(symbol) or
find_file_named(symbol)
@store.find_file_named(symbol)
end

##
Expand Down
13 changes: 0 additions & 13 deletions lib/rdoc/code_object/method_attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,6 @@ def name_prefix
@singleton ? '::' : '#'
end

##
# Name for output to HTML. For class methods the full name with a "." is
# used like +SomeClass.method_name+. For instance methods the class name is
# used if +context+ does not match the parent.
#
# This is to help prevent people from using :: to call class methods.

def output_name context
return "#{name_prefix}#{@name}" if context == parent

"#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
end

##
# Method/attribute name with class/instance indicator

Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/code_object/require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def inspect # :nodoc:
self.class,
object_id,
@name,
parent_file_name,
@parent ? @parent.base_name : '(unknown)'
]
end

Expand Down
18 changes: 0 additions & 18 deletions lib/rdoc/code_object/top_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context

MARSHAL_VERSION = 0 # :nodoc:

##
# This TopLevel's File::Stat struct

attr_accessor :file_stat

##
# Relative name of this file

Expand All @@ -28,8 +23,6 @@ class RDoc::TopLevel < RDoc::Context

attr_reader :classes_or_modules

attr_accessor :diagram # :nodoc:

##
# The parser class that processed this file

Expand All @@ -45,8 +38,6 @@ def initialize absolute_name, relative_name = absolute_name
@name = nil
@absolute_name = absolute_name
@relative_name = relative_name
@file_stat = File.stat(absolute_name) rescue nil # HACK for testing
@diagram = nil
@parser = nil

@classes_or_modules = []
Expand Down Expand Up @@ -186,13 +177,6 @@ def inspect # :nodoc:
]
end

##
# Time this file was last modified, if known

def last_modified
@file_stat ? file_stat.mtime : nil
end

##
# Dumps this TopLevel for use by ri. See also #marshal_load

Expand All @@ -213,8 +197,6 @@ def marshal_load array # :nodoc:

@parser = array[2]
@comment = RDoc::Comment.from_document array[3]

@file_stat = nil
end

##
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/generator/pot/message_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def extract_from_klass klass
end
end

klass.each_constant do |constant|
klass.constants.each do |constant|
extract_text(constant.comment, constant.full_name)
end

klass.each_attribute do |attribute|
klass.attributes.each do |attribute|
extract_text(attribute.comment, attribute.full_name)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h3>Extended With Modules</h3>

<ul class="link-list">
<%- klass.each_extend do |ext| -%>
<%- klass.extends.each do |ext| -%>
<%- unless String === ext.module then -%>
<li><a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a>
<%- else -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h3>Included Modules</h3>

<ul class="link-list">
<%- klass.each_include do |inc| -%>
<%- klass.includes.each do |inc| -%>
<%- unless String === inc.module then -%>
<li><a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a>
<%- else -%>
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def report_attributes cm

report = []

cm.each_attribute do |attr|
cm.attributes.each do |attr|
next if attr.documented?
line = attr.line ? ":#{attr.line}" : nil
report << " #{attr.definition} :#{attr.name} # in file #{attr.file.full_name}#{line}\n"
Expand Down Expand Up @@ -331,7 +331,7 @@ def report_constants cm

report = []

cm.each_constant do |constant|
cm.constants.each do |constant|
# TODO constant aliases are listed in the summary but not reported
# figure out what to do here
next if constant.documented? || constant.is_alias_for
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def save
save_method klass, method
end

klass.each_attribute do |attribute|
klass.attributes.each do |attribute|
save_method klass, attribute
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/rdoc/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ def test_update_extends
@c1.add_extend a
@c1.add_extend b
@c1.add_extend c
@c1.each_extend do |extend| extend.module end # cache extended modules
@c1.extends.each do |extend| extend.module end # cache extended modules

@m1_m2.document_self = nil
assert @m1_m2.remove_from_documentation?
Copy link
Member Author

Choose a reason for hiding this comment

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

These same test assertions actually appear in other tests like test_update_includes_with_colons as well. So we don't need to keep them here either.

Expand All @@ -1495,7 +1495,7 @@ def test_update_extends_trim

@c1.add_extend a
@c1.add_extend b
@c1.each_extend do |extend| extend.module end # cache extended modules
@c1.extends.each do |extend| extend.module end # cache extended modules

@c1.update_extends

Expand All @@ -1510,7 +1510,7 @@ def test_update_extends_with_colons
@c1.add_extend a
@c1.add_extend b
@c1.add_extend c
@c1.each_extend do |extend| extend.module end # cache extended modules
@c1.extends.each do |extend| extend.module end # cache extended modules

@m1_m2.document_self = nil
assert @m1_m2.remove_from_documentation?
Expand Down
15 changes: 0 additions & 15 deletions test/rdoc/test_rdoc_code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,6 @@ def test_done_documenting
refute @co.done_documenting
end

def test_each_parent
parents = []

@parent_m.each_parent do |code_object|
parents << code_object
end

assert_equal [@parent, @xref_data], parents
end

def test_file_name
assert_nil @co.file_name

Expand Down Expand Up @@ -275,11 +265,6 @@ def test_metadata
assert_equal 'not_rdoc', @co.metadata['markup']
end

def test_parent_file_name
assert_equal '(unknown)', @co.parent_file_name
assert_equal 'xref_data.rb', @c1.parent_file_name
end

def test_parent_name
assert_equal '(unknown)', @co.parent_name
assert_equal 'xref_data.rb', @c1.parent_name
Expand Down
11 changes: 0 additions & 11 deletions test/rdoc/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,6 @@ def test_current_section
assert_equal default_section, @context.current_section
end

def test_defined_in_eh
assert @c1.defined_in?(@c1.top_level)

refute @c1.defined_in?(@store.add_file('name.rb'))
end

def test_equals2
assert_equal @c3, @c3
refute_equal @c2, @c3
Expand Down Expand Up @@ -538,11 +532,6 @@ def test_find_enclosing_module_named
assert_equal @c2, @c2_c3.find_enclosing_module_named('C2')
end

def test_find_file_named
assert_nil @c1.find_file_named('nonexistent.rb')
assert_equal @xref_data, @c1.find_file_named(@file_name)
end

def test_find_instance_method_named
assert_nil @c1.find_instance_method_named('none')

Expand Down
Loading
Loading