Prism parser no longer accepts legacy ghost method directives without a leading colon
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- ruby
调研方向
从 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/rdoc 的其他 Issue
-
RDoc 8.0.0 gem omits `doc/rdoc/example.rb`, which is referenced by the packaged markup documentation 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 85/100
-
enhancement
难度 4/5 3-5 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 5/5 一周以上 新手友好度 35/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
TheOdinProject/curriculum#31423 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
oxidize-rb/rb-sys#807 ·
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
-
ai-generated
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 75/100