From 05ed61c42e622e8bbe32306c3adcf80335d33d0e Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 12 Mar 2026 19:56:15 +0000 Subject: [PATCH 1/2] Remove dead constants and unused AnonClass (#1642) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Remove `RDoc::AnonClass` class and file (documented as "never used") - Remove `Darkfish::VERSION` (unreferenced) - Remove `Formatter::InlineTag` struct (unused after inline parser rewrite) - Remove `ToHtmlCrossref::CLASS_REGEXP_STR` and `METHOD_REGEXP_STR` (aliased but unused within the file) ### Process & tools used 1. **Detect candidates** — Used `detect_dead_constants` from [Rubydex](https://github.com/Shopify/rubydex) to find constants with zero resolved references in `lib/`. Got 22 candidates. 2. **Filter out false positives** — Grepped for actual usage of each candidate, catching private constants used internally, dynamic access via `const_defined?`/`const_get`, default parameters, and generated code (Racc). 3. **Remove confirmed dead code** — Deleted 5 constants and 1 class+file. 4. **Run full test suite** — Caught that one deletion (`RI::Formatter`) broke a `require_relative` in `ri/driver.rb`, so restored it. Final run: 2384 tests, 0 failures. --- lib/rdoc.rb | 1 - lib/rdoc/code_object.rb | 1 - lib/rdoc/code_object/anon_class.rb | 10 ---------- lib/rdoc/generator/darkfish.rb | 5 ----- lib/rdoc/markup/formatter.rb | 7 ------- lib/rdoc/markup/to_html_crossref.rb | 2 -- 6 files changed, 26 deletions(-) delete mode 100644 lib/rdoc/code_object/anon_class.rb diff --git a/lib/rdoc.rb b/lib/rdoc.rb index b42059c712..d93d79e4d1 100644 --- a/lib/rdoc.rb +++ b/lib/rdoc.rb @@ -189,7 +189,6 @@ def self.home autoload :Context, "#{__dir__}/rdoc/code_object/context" autoload :TopLevel, "#{__dir__}/rdoc/code_object/top_level" - autoload :AnonClass, "#{__dir__}/rdoc/code_object/anon_class" autoload :ClassModule, "#{__dir__}/rdoc/code_object/class_module" autoload :NormalClass, "#{__dir__}/rdoc/code_object/normal_class" autoload :NormalModule, "#{__dir__}/rdoc/code_object/normal_module" diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index 4f5a998fc6..c15c0129f5 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -10,7 +10,6 @@ # * RDoc::Context # * RDoc::TopLevel # * RDoc::ClassModule -# * RDoc::AnonClass (never used so far) # * RDoc::NormalClass # * RDoc::NormalModule # * RDoc::SingleClass diff --git a/lib/rdoc/code_object/anon_class.rb b/lib/rdoc/code_object/anon_class.rb deleted file mode 100644 index 3c2f0e1877..0000000000 --- a/lib/rdoc/code_object/anon_class.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -## -# An anonymous class like: -# -# c = Class.new do end -# -# AnonClass is currently not used. - -class RDoc::AnonClass < RDoc::ClassModule -end diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index e3f45deeab..574918500f 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -73,11 +73,6 @@ class RDoc::Generator::Darkfish css/rdoc.css ] - ## - # Release Version - - VERSION = '3' - ## # Description of this generator diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index 433237393d..0532fae5fc 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -14,13 +14,6 @@ class RDoc::Markup::Formatter - ## - # Tag for inline markup containing a +bit+ for the bitmask and the +on+ and - # +off+ triggers. - - InlineTag = Struct.new(:bit, :on, :off) - - ## # Converts a target url to one that is relative to a given path diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index 6e0d0793be..e088303801 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -8,9 +8,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml # :stopdoc: ALL_CROSSREF_REGEXP = RDoc::CrossReference::ALL_CROSSREF_REGEXP - CLASS_REGEXP_STR = RDoc::CrossReference::CLASS_REGEXP_STR CROSSREF_REGEXP = RDoc::CrossReference::CROSSREF_REGEXP - METHOD_REGEXP_STR = RDoc::CrossReference::METHOD_REGEXP_STR # :startdoc: ## From d7d58e6c7f25126a7ec75e35f400fdaeaee332f5 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 12 Mar 2026 21:11:44 +0100 Subject: [PATCH 2/2] Fix section comments with the prism parser (#1639) The section expects a non-formatted comment. Closes https://github.com/ruby/rdoc/issues/1638 Can be simplified once the ripper parser is removed. It currently passes the comment text as is and transforms it in the section class itself. The prism parser now does it outside of that class. --- lib/rdoc/code_object/context/section.rb | 3 +++ lib/rdoc/parser/prism_ruby.rb | 17 ++++++++++-- test/rdoc/parser/prism_ruby_test.rb | 35 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/code_object/context/section.rb b/lib/rdoc/code_object/context/section.rb index 05e7c688bc..cf91be9d81 100644 --- a/lib/rdoc/code_object/context/section.rb +++ b/lib/rdoc/code_object/context/section.rb @@ -106,6 +106,9 @@ def legacy_aref # # # :section: The title # # The body + # + #-- + # TODO Remove when the ripper parser has been removed def extract_comment(comment) case comment diff --git a/lib/rdoc/parser/prism_ruby.rb b/lib/rdoc/parser/prism_ruby.rb index 9ff93eacd6..e8dedd5c18 100644 --- a/lib/rdoc/parser/prism_ruby.rb +++ b/lib/rdoc/parser/prism_ruby.rb @@ -473,15 +473,28 @@ def parse_comment_text_to_directives(comment_text, start_line) # :nodoc: comment.line = start_line markup, = directives['markup'] comment.format = markup&.downcase || @markup - if (section, = directives['section']) + if (section, directive_line = directives['section']) # If comment has :section:, it is not a documentable comment for a code object - @container.set_current_section(section, comment.dup) + comment.text = extract_section_comment(comment_text, directive_line - start_line) + @container.set_current_section(section, comment) return end @preprocess.run_post_processes(comment, @container) [comment, directives] end + # Extracts the comment for this section from the normalized comment block. + # Removes all lines before the line that contains :section: + # If the comment also ends with the same content, remove it as well + + def extract_section_comment(comment_text, prefix_line_count) # :nodoc: + prefix = comment_text.lines[0...prefix_line_count].join + comment_text.delete_prefix!(prefix) + # Comment is already normalized and doesn't end with a newline + comment_text.delete_suffix!(prefix.chomp) + comment_text + end + def slice_tokens(start_pos, end_pos) # :nodoc: start_index = @tokens.bsearch_index { |t| ([t.line_no, t.char_no] <=> start_pos) >= 0 } end_index = @tokens.bsearch_index { |t| ([t.line_no, t.char_no] <=> end_pos) >= 0 } diff --git a/test/rdoc/parser/prism_ruby_test.rb b/test/rdoc/parser/prism_ruby_test.rb index d336b4e740..f018123f7b 100644 --- a/test/rdoc/parser/prism_ruby_test.rb +++ b/test/rdoc/parser/prism_ruby_test.rb @@ -36,6 +36,41 @@ def test_look_for_directives_in_section assert_equal 'new section', section.title end + def test_section_with_divider + util_parser <<~RUBY + # DIVIDER + # :section: section 1 + # foo + # DIVIDER + + # DIVIDER 1 + # DIVIDER 2 + # :section: section 2 + # foo + # DIVIDER 1 + # DIVIDER 2 + + # DIVIDER TOP ONLY + # :section: section 3 + # foo + + # DIVIDER TOP ONLY + # :section: section 4 + RUBY + + section = @top_level.sections_hash['section 1'] + assert_equal "\n

foo

\n", section.description + + section = @top_level.sections_hash['section 2'] + assert_equal "\n

foo

\n", section.description + + section = @top_level.sections_hash['section 3'] + assert_equal "\n

foo

\n", section.description + + section = @top_level.sections_hash['section 4'] + assert_equal '', section.description + end + def test_look_for_directives_in_commented util_parser <<~RUBY # how to make a section: