Option to omit private methods from gem RBIs, with a per-gem opt-in
维护者通常 4 天内回复
评估
调研方向
Start with the Methods listener that skips private methods during tapioca gem and with merge_with_exported_rbi, which the issue says must run after filtering. Read how typed_overrides is parsed from the config to model the new gem options. Done means private_methods: false omits private methods except for gems in private_methods_for, and gems that export their own RBIs keep their private markers after the merge.
由索引模型根据 Issue 内容生成。
描述
Problem
tapioca gem emits every private method it finds. Application code only reaches a gem's private methods through implicit-receiver calls from subclasses, including modules, or DSLs like Rake::DSL, so for most gems these definitions add size and diff churn without affecting type checking.
In a large Rails app (501 gems in the bundle, RBIs generated for 395), 332 of the generated RBIs contain private methods. After stripping private methods from all of them, srb tc passes once private methods are restored for just 9 gems:
rake:Rake::DSL#task,#namespace,#desc, called at the top level of every.rakefileactiverecord:default_scope,transaction_include_any_action?tapioca:Tapioca::Dsl::Compiler#compile_method_parameters_to_rbi,#compile_method_return_type_to_rbi,.all_classes, used by custom DSL compilersrbi:RBI::Visitor#visit_*, whichRBI::RBSPrinteroverrides withoverridesigs in the gem's own RBIkarafka:Karafka::Instrumentation::Vendors::Datadog::MetricsListener#consumer_tagsand#namespaced_metric, overridden by a subclass in another gemsuper_diff,shoulda-matchers,rubocop, and one internal gem: helpers called from subclasses
Potential reduction
Keeping private methods for those 9 gems and omitting them for the other 386:
| Before | After | Change | |
|---|---|---|---|
| Method definitions | 198,737 | 177,402 | -10.7% |
| RBI size, excluding comments | 14.3 MB | 13.3 MB | -7.2% |
| RBI size, total | 38.8 MB | 37.0 MB | -4.8% |
| RBI lines, total | 1,082,949 | 1,020,568 | -5.8% |
Gem upgrades that only touch private methods would also stop producing RBI diffs.
Proposal
A gem option that turns private methods off, plus a list of gems that keep them, similar in shape to typed_overrides:
gem:
private_methods: false
private_methods_for:
- rake
- activerecord
Defaulting private_methods to true keeps today's output.
Implementation note
We prototyped this with a patch loaded from sorbet/tapioca/require.rb. The filtering has to run after merge_with_exported_rbi. When the Methods listener skips private methods instead, gems that export their own RBIs (pdf-reader, rbi, spoom, prism) declare many of those methods without a private marker, and the merge brings them back as public methods.
Happy to open a PR if this sounds reasonable.
- 主要语言
- Ruby
- 星标
- 874
- 派生
- 167
- 平均合并
- 5 天 12 小时
- 30 天内合并 PR
- 11
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Shopify/tapioca 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
Shopify/tapioca#2662 · 1 条评论 ·
维护者通常 4 天内回复
-
难度 3/5 1-2 天 新手友好度 57/100
维护者通常 4 天内回复
-
Improve `check-shims` performance可能已有人在做 @KaanOzkan 于 17 天前认领。 未关闭
Shopify/tapioca#2728 · 已指派 1 人 ·
维护者通常 4 天内回复
-
难度 5/5 一周以上 新手友好度 30/100
维护者通常 4 天内回复
-
Prepending a module can cause `tapioca dsl` to produce an untyped signature可能已有人在做 @KaanOzkan 于 52 天前认领。 未关闭bug
Shopify/tapioca#2705 · 已指派 1 人 ·
维护者通常 4 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 2/5 1-3 小时 新手友好度 68/100
-
:bank: debt
难度 2/5 1-3 小时 新手友好度 75/100
cucumber/cucumber-ruby-core#346 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 75/100
TheOdinProject/curriculum#31467 · 2 条评论 ·
维护者通常 1 天内回复
-
message-patterns
难度 2/5 1-3 小时 新手友好度 65/100
sisimai/rb-sisimai#468 ·