Skip to content

Comments

Refactor formatter options#1623

Merged
st0012 merged 2 commits intomasterfrom
refactor-formatter-options
Feb 22, 2026
Merged

Refactor formatter options#1623
st0012 merged 2 commits intomasterfrom
refactor-formatter-options

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Feb 22, 2026

  1. The markup param is never actually used. So let's drop it
  2. Instead of holding Option objects, formatters should just take the relevant option values. This will unlock further refactors to decouple CodeObject and Store later.

No caller ever passes a non-nil `markup` to any formatter constructor —
every formatter creates its own `RDoc::Markup.new` internally.

Remove the `markup` parameter from `Formatter#initialize` and all
subclasses: `ToHtml`, `ToHtmlCrossref`, `ToHtmlSnippet`, `ToRdoc`,
`ToLabel`, `ToTtOnly`, `ToAnsi`, `ToBs`, `ToMarkdown`.

Also remove the dead `markup` variable in `Heading.to_html` that was
configured with crossref regexp handling but never passed to the
formatter.
@matzbot
Copy link
Collaborator

matzbot commented Feb 22, 2026

🚀 Preview deployment available at: https://fe8cd161.rdoc-6cd.pages.dev (commit: 7c47d0a)

@st0012 st0012 marked this pull request as ready for review February 22, 2026 14:43
Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

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

Looks great 👍

`Formatter#initialize` took an `RDoc::Options` object, but only 2
subclasses (`ToHtml`, `ToHtmlCrossref`) read from it — using just 6
specific boolean/array values. All other formatters passed `nil`.

Replace the `options` parameter with explicit keyword arguments:
- `ToHtml`: `pipe:`, `output_decoration:`
- `ToHtmlCrossref`: `pipe:`, `output_decoration:`, `hyperlink_all:`,
  `show_hash:`, `autolink_excluded_words:`, `warn_missing_rdoc_ref:`

Call sites (`Generator::Markup#formatter`, `RDoc::RDoc#handle_pipe`)
now unpack the needed values from `RDoc::Options` at the boundary.

`ToHtmlSnippet` and `Text#snippet` no longer receive or forward options.

Delete `LinkLabelToHtml` (zero callers in the codebase).

Update `CodeObject#options` comment to reflect remaining callers.
@st0012 st0012 force-pushed the refactor-formatter-options branch from 7c05c1f to 7c47d0a Compare February 22, 2026 16:07
@st0012 st0012 merged commit 08036aa into master Feb 22, 2026
68 checks passed
@st0012 st0012 deleted the refactor-formatter-options branch February 22, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants