Skip to content

Fix circular require of RDoc::Parser::RubyColorizer#1709

Merged
tompng merged 1 commit into
ruby:masterfrom
tompng:fix_colorizer_circular_require
May 12, 2026
Merged

Fix circular require of RDoc::Parser::RubyColorizer#1709
tompng merged 1 commit into
ruby:masterfrom
tompng:fix_colorizer_circular_require

Conversation

@tompng
Copy link
Copy Markdown
Member

@tompng tompng commented May 12, 2026

Loading RubyColorizer will trigger autoload of RDoc::Parser, and require_relative 'parser/ruby'.
parser/ruby.rb shouldn't require ruby_colorizer.rb to avoid circular require.

Originally found in rake test log, but can be reproduced with:

$ ruby -W -rrdoc -Ilib -e 'p RDoc::Markup::ToHtml'
warning: loading in progress, circular require considered harmful

Copilot AI review requested due to automatic review settings May 12, 2026 13:05
@tompng tompng temporarily deployed to fork-preview-protection May 12, 2026 13:05 — with GitHub Actions Inactive
@matzbot
Copy link
Copy Markdown
Collaborator

matzbot commented May 12, 2026

🚀 Preview deployment available at: https://caa4c640.rdoc-6cd.pages.dev (commit: 47f155f)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a circular require warning triggered when autoloading RDoc::Markup::ToHtml (via require 'rdoc') by removing direct ruby_colorizer requires that caused RDoc::Parser to be autoloaded mid-load.

Changes:

  • Removed ruby_colorizer requires from RDoc::Parser::Ruby and RDoc::Markup::ToHtml to break the problematic load chain.
  • Added parser/ruby_colorizer loading to lib/rdoc/parser.rb so the colorizer is available when the parser is loaded.
  • Updated the RubyColorizer test to rely on autoloading instead of directly requiring the colorizer.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
test/rdoc/parser/ruby_colorizer_test.rb Stops requiring rdoc/parser/ruby_colorizer directly in tests.
lib/rdoc/parser/ruby.rb Removes require_relative 'ruby_colorizer' to avoid circular require.
lib/rdoc/parser.rb Loads parser/ruby_colorizer from the parser entrypoint.
lib/rdoc/markup/to_html.rb Removes direct require of rdoc/parser/ruby_colorizer to avoid triggering circular require during autoload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/rdoc/parser.rb
Comment on lines 293 to +297
require_relative 'parser/changelog'
require_relative 'parser/markdown'
require_relative 'parser/rd'

require_relative 'parser/ruby'
require_relative 'parser/ruby_colorizer'
Comment on lines 1 to 5
# frozen_string_literal: true
require 'cgi/escape'
require 'cgi/util' unless defined?(CGI::EscapeExt)
require 'prism'
require 'rdoc/parser/ruby_colorizer'

Comment thread test/rdoc/parser/ruby_colorizer_test.rb
Loading RubyColorizer will trigger autoload of RDoc::Parser, and `require_relative 'parser/ruby'`.
`parser/ruby.rb` shouldn't require `ruby_colorizer.rb` to avoid circular require.
@tompng tompng force-pushed the fix_colorizer_circular_require branch from 82fff09 to 47f155f Compare May 12, 2026 13:22
@tompng tompng deployed to fork-preview-protection May 12, 2026 13:22 — with GitHub Actions Active
@tompng tompng merged commit 29b8942 into ruby:master May 12, 2026
41 checks passed
@tompng tompng deleted the fix_colorizer_circular_require branch May 12, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants