Skip to content

Prism parser no longer accepts legacy ghost method directives without a leading colon #1760

Open

Description

@thyresias

Description

The previous Ruby parser accepted ghost/meta directives both with and without
an initial colon:

# method: foo
# :method: foo

RDoc 8.0.0 only recognizes the canonical second form.

Although the form without the initial colon is not the currently documented
syntax, the previous parser explicitly supported it. Existing documentation
relies on this behavior.

Minimal reproduction

class Example
  ##
  # method: legacy_method
  # A legacy ghost method directive.

  ##
  # :method: canonical_method
  # A canonical ghost method directive.
end

With RDoc 6.17.0:

Example.method_list.map(&:name)
# => ["legacy_method", "canonical_method"]

With RDoc 8.0.0:

Example.method_list.map(&:name)
# => ["canonical_method"]

The previous parser deliberately made the initial colon optional:

/^# +:?method:/

It did the same for singleton-method and attribute directives.

Real-world example

net-imap documents members created dynamically by Struct using this
syntax:

##
# method: media_type
# :call-seq: media_type -> string

Source:

https://github.com/ruby/net-imap/blob/v0.6.4.1/lib/net/imap/response_data.rb#L903

RDoc 8 does not create the ghost method, so references such as:

rdoc-ref:BodyTypeBasic#media_type

cannot be resolved.

Expected behavior

For backward compatibility, the Prism parser should recognize both:

# method: foo
# :method: foo

The same compatibility should apply to:

method
singleton-method
attr
attr_reader
attr_writer
attr_accessor

Suggested fix

Before passing Ruby comments to the common directive parser, normalize legacy
meta directives to their canonical form.

For example:

LEGACY_META_DIRECTIVE =
  /^([ \t]*\#[ \t]+)(singleton-method|method|attr(?:_reader|_writer|_accessor)?):/i

A match can be rewritten from:

# method: foo

to:

# :method: foo

Canonical directives must remain unchanged.

Tests should cover both forms for methods, singleton methods, and attributes.

Environment

Ruby 4.0.5 +PRISM
RDoc 8.0.0
Prism 1.9.0

Activity

  1. skatkov commented on Jul 31, 2026

    @skatkov
    Contributor

    Should this be raised with prism parser instead?

  2. thyresias commented on Jul 31, 2026

    @thyresias
    Author

    Should this be raised with prism parser instead?

    No, this is an RDoc regression that arrived when switching to Prism. Prism does not handle RDoc comments.

  3. tompng commented on Jul 31, 2026

    @tompng
    Member

    Sorry for the inconvience of this behavior change.
    Leading-colon-less directive may unintentionally match to a normal source code comment.
    For example, there are many "# method: " comments which is not meant to be an RDoc directive.
    Code search: "# method:"

    # method: description of method parameter named `method` (e.g. :put or :post)
    
    # Long line that describes about some
    # method:
    #   p some() #=> :some

    Since it was never documented, I'd like to keep the behavior introduced in this new major version 8.0.

  4. thyresias commented on Jul 31, 2026

    @thyresias
    Author

    Ok, but in that case, shouldn't there be warnings about such constructs, that used to work?

  5. nevans commented on Aug 26, 2026

    @nevans
    Contributor

    I agree with @thyresias. It took me a while to 1) notice a bunch of documentation had disappeared, and 2) track down whether or not it was intentional.

    While I understand the reason for changing the behavior, the old RDoc::Parser::Ruby#parse_comment in rdoc 7.2 definitely seemed intentional (and I used it quite a bit). At the very least, the "Breaking Changes" section in the v8.0 release notes should be updated!

  6. nevans commented on Aug 26, 2026

    @nevans
    Contributor

    Also, haha! I only just noticed that the example in this ticket was literally documentation that I'd written. Please feel free to open broken documentation issues (or PRs) with net-imap, too... even if it is an undocumented breaking change in rdoc. 😉 I hadn't noticed that net-imap's documentation had been broken by rdoc 8.0 until yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions