Skip to content

Commit

Permalink
Remove unnecessary file_name parameter from Parser#initialize (#1146
Browse files Browse the repository at this point in the history
)

Similar to #1135, the `file_name` argument's value should be the name as
`top_level.absolute_name`. So passing it separately is not necessary.
  • Loading branch information
st0012 authored Jan 27, 2025
1 parent 8686aa7 commit 75d1511
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 23 deletions.
6 changes: 3 additions & 3 deletions lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def self.for top_level, content, options, stats

content = remove_modeline content

parser.new top_level, file_name, content, options, stats
parser.new top_level, content, options, stats
rescue SystemCallError
nil
end
Expand Down Expand Up @@ -252,12 +252,12 @@ def self.use_markup content
# RDoc::Markup::PreProcess object is created which allows processing of
# directives.

def initialize top_level, file_name, content, options, stats
def initialize top_level, content, options, stats
@top_level = top_level
@top_level.parser = self.class
@store = @top_level.store

@file_name = file_name
@file_name = top_level.absolute_name
@content = content
@options = options
@stats = stats
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class RDoc::Parser::C < RDoc::Parser
# Prepares for parsing a C file. See RDoc::Parser#initialize for details on
# the arguments.

def initialize top_level, file_name, content, options, stats
def initialize top_level, content, options, stats
super

@known_classes = RDoc::KNOWN_CLASSES.dup
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser/prism_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
attr_accessor :visibility
attr_reader :container, :singleton

def initialize(top_level, file_name, content, options, stats)
def initialize(top_level, content, options, stats)
super

content = handle_tab_width(content)
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Creates a new Ruby parser.

def initialize(top_level, file_name, content, options, stats)
def initialize(top_level, content, options, stats)
super

content = handle_tab_width(content)
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RDoc::Parser::Simple < RDoc::Parser
##
# Prepare to parse a plain file

def initialize(top_level, file_name, content, options, stats)
def initialize(top_level, content, options, stats)
super

preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
Expand Down
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_class_use_markup_unknown

def test_initialize
with_top_level("file.rb", "") do |top_level, content|
@RP.new top_level, top_level.absolute_name, content, @options, nil
@RP.new top_level, content, @options, nil

assert_equal @RP, top_level.parser
end
Expand Down
4 changes: 2 additions & 2 deletions test/rdoc/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_initialize
@fn => { 'cSomeExtSingle' => 'SomeExtSingle' }
}

parser = RDoc::Parser::C.new @top_level, @fn, '', @options, @stats
parser = RDoc::Parser::C.new @top_level, '', @options, @stats

expected = { 'cSomeExt' => some_ext }
assert_equal expected, parser.classes
Expand Down Expand Up @@ -2144,7 +2144,7 @@ def util_get_class content, name = nil
end

def util_parser content = ''
RDoc::Parser::C.new @top_level, @fn, content, @options, @stats
RDoc::Parser::C.new @top_level, content, @options, @stats
end

end
3 changes: 1 addition & 2 deletions test/rdoc/test_rdoc_parser_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ def test_scan_git_commit_date
end

def util_parser content = ''
RDoc::Parser::ChangeLog.new \
@top_level, @tempfile.path, content, @options, @stats
RDoc::Parser::ChangeLog.new @top_level, content, @options, @stats
end

def log_entry(*a)
Expand Down
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_parser_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_scan
end

def util_parser content
RDoc::Parser::Markdown.new @top_level, @fn, content, @options, @stats
RDoc::Parser::Markdown.new @top_level, content, @options, @stats
end

end
4 changes: 2 additions & 2 deletions test/rdoc/test_rdoc_parser_prism_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ def accept_legacy_bug?
end

def util_parser(content)
@parser = RDoc::Parser::PrismRuby.new @top_level, @filename, content, @options, @stats
@parser = RDoc::Parser::PrismRuby.new @top_level, content, @options, @stats
@parser.scan
end
end
Expand All @@ -2010,7 +2010,7 @@ def accept_legacy_bug?
end

def util_parser(content)
@parser = RDoc::Parser::Ruby.new @top_level, @filename, content, @options, @stats
@parser = RDoc::Parser::Ruby.new @top_level, content, @options, @stats
@parser.scan
end
end unless ENV['RDOC_USE_PRISM_PARSER']
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_parser_rd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_scan
end

def util_parser content
RDoc::Parser::RD.new @top_level, @fn, content, @options, @stats
RDoc::Parser::RD.new @top_level, content, @options, @stats
end

end
3 changes: 1 addition & 2 deletions test/rdoc/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4087,8 +4087,7 @@ class Baz
end

def util_parser(content)
@parser = RDoc::Parser::Ruby.new @top_level, @filename, content, @options,
@stats
@parser = RDoc::Parser::Ruby.new @top_level, content, @options, @stats
end

def util_two_parsers(first_file_content, second_file_content)
Expand Down
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_parser_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_scan
end

def util_parser(content)
RDoc::Parser::Simple.new @top_level, @fn, content, @options, @stats
RDoc::Parser::Simple.new @top_level, content, @options, @stats
end

end
4 changes: 2 additions & 2 deletions test/rdoc/test_rdoc_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_add_c_variables
some_ext = c_file.add_class RDoc::NormalClass, 'SomeExt'
c_file.add_class RDoc::SingleClass, 'SomeExtSingle'

c_parser = RDoc::Parser::C.new c_file, 'ext.c', '', options, nil
c_parser = RDoc::Parser::C.new c_file, '', options, nil

c_parser.classes['cSomeExt'] = some_ext
c_parser.singleton_classes['s_cSomeExt'] = 'SomeExtSingle'
Expand Down Expand Up @@ -698,7 +698,7 @@ def test_save_cache
some_ext = c_file.add_class RDoc::NormalClass, 'SomeExt'
c_file.add_class RDoc::SingleClass, 'SomeExtSingle'

c_parser = RDoc::Parser::C.new c_file, 'ext.c', '', options, nil
c_parser = RDoc::Parser::C.new c_file, '', options, nil

c_parser.classes['cSomeExt'] = some_ext
c_parser.singleton_classes['s_cSomeExt'] = 'SomeExtSingle'
Expand Down
3 changes: 1 addition & 2 deletions test/rdoc/xref_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def setup

stats = RDoc::Stats.new @store, 0

parser = RDoc::Parser::Ruby.new @xref_data, @file_name, XREF_DATA, @options,
stats
parser = RDoc::Parser::Ruby.new @xref_data, XREF_DATA, @options, stats

@example_md = @store.add_file 'EXAMPLE.md'
@example_md.parser = RDoc::Parser::Markdown
Expand Down

0 comments on commit 75d1511

Please sign in to comment.