Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#1,760 6 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ruby
领域
documentation

调研方向

从 Prism 解析器的注释处理开始,跟踪注释如何到达通用指令解析器。添加测试,覆盖 legacy 和 canonical 方法、singleton-method 以及属性指令,然后验证两种形式都会生成预期的成员,并保留 canonical 指令。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Ruby
星标
930
派生
465
平均合并
3 天 10 小时
30 天内合并 PR
27

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/rdoc 的其他 Issue

查看 ruby/rdoc 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。