Skip to content

Markdown 対応で追加されたコードに RBS 型定義を付ける#231

Merged
znz merged 1 commit into
rurema:masterfrom
znz:rbs-markdown-sigs
Jul 11, 2026
Merged

Markdown 対応で追加されたコードに RBS 型定義を付ける#231
znz merged 1 commit into
rurema:masterfrom
znz:rbs-markdown-sigs

Conversation

@znz

@znz znz commented Jul 11, 2026

Copy link
Copy Markdown
Member

解決したい問題

Markdown 移行(#189 以降)で追加されたコードに RBS 型定義が無く、
型検査の網羅性チェックである rake sig が失敗する状態でした
(rbs subtract の残余が 18 ファイル分)。steep check
エラー 471 件・警告 317 件を報告しており、そのほぼ全てが
markdown 対応の型付け漏れ由来でした(新規クラスの宣言欠落、
既存クラスに追加された markdown 系メソッドの sig 未追記、およびその波及)。

変更内容

sig の新規作成(13 ファイル)

markdown パイプラインの全クラスを既存 sig と同じ流儀
(ivar 宣言・private 対応・type エイリアス・実型優先)で型付けしました:

  • パース/描画: mdparser(MDParser / MDFunctionParser)、mdcompiler
  • 記法変換: markdown_to_rrdrrd_to_markdowncapi_converterdoc_converter
  • ツリー/ブリッジ: markdown_treemarkdown_bridgemarkdown_orchestrator
  • include 解析: include_graphinclude_prunerentity_splitterwhole_file_gate

untyped は本当に動的な箇所(混在 arity のトークン列など)だけに限定し、
理由をコメントで残しています。

既存 sig への追記・修正

  • markdown 対応で増えたメンバーの追記:
    MethodDatabase#update_by_markdowntree/#copy_doc_md
    FunctionDatabase#update_by_markdowntree
    TemplateScreen#markdown_source?/#html_base
    UpdateCommand#prepare_markdowntree ほか、
    StatichtmlCommand#create_search_index/SEARCH_JS_FILES
  • database_propkey'source_format' を追加
  • Rouge の最小スタブ sig/rouge.rbs を追加(Rouge を導入して ruby 以外の言語のシンタックスハイライトに対応する #223 で導入した
    Lexer.find/tag/lexFormatters::HTML#format のみ)
  • 実装と食い違っていた既存 sig の修正:
    RDCompiler::option:catalog を省略可へ(実装はフォールバック持ち)、
    LocationlineInteger? へ(行不明の Location が実在)、
    Entry#display_text/#description_text をオーバーロード化
    ((String) -> String | (String?) -> String?)、
    searchpage_command.rbs の型名修飾漏れ(argvSubcommand::argv
    これが原因で同ファイルの lib 側チェック自体が走っていませんでした)

lib 側(挙動の変更はありません)

  • マッチ直後で非 nil が保証される $1 等の参照・Array の Range スライスは、
    コードベース既存慣行の ($1 || raise)に統一(rrdparser.rb に先例)
  • steep が推論できない空リテラルやループ越し代入にインライン注釈
    (#: Array[String] / # @type var)を追加
  • #: 型 注釈の直後に説明文が続いて注釈のパースが壊れていた既存 2 箇所を修復
    (説明文を前行コメントへ分離)
  • rbs core の型が Pathname を受けない File.read/File.write
    Pathname#read/#write に書き換え(searchpage_command)

検証

検査 Before After
bundle exec rake sig 失敗(残余 18 ファイル) ✅ 通過
bundle exec steep check エラー 471・警告 317 エラー 0・警告 0
bundle exec rbs validate ✅ 通過
ruby test/run_test.rb ✅ 17,589 tests / 0 failures

🤖 Generated with Claude Code

rake sig(rbs subtract)が検出する型定義の不足を解消する:

- Markdown 対応で追加された 13 ファイル分の sig を新規作成
  (mdparser, mdcompiler, markdown_to_rrd, rrd_to_markdown,
    markdown_tree, markdown_bridge, markdown_orchestrator,
    include_graph, include_pruner, entity_splitter, whole_file_gate,
    capi_converter, doc_converter)
- 既存クラスに追加された markdown 系メンバーを既存 sig へ追記
  (MethodDatabase#update_by_markdowntree・copy_doc_md、
    TemplateScreen#markdown_source?・html_base、
    UpdateCommand#prepare_markdowntree ほか、
    StatichtmlCommand#create_search_index・SEARCH_JS_FILES)
- database_propkey へ 'source_format' を追加、Rouge の最小スタブを追加、
  RDCompiler::option の :catalog を実装に合わせて省略可へ、
  Location の line を Integer? へ(line 不明の Location があるため)

steep check をエラー 0・警告 0 にする(従来はエラー 471・警告 317):

- マッチ直後で非 nil が保証される $1 等の参照は
  既存慣行の ($1 || raise) 形に揃える
- steep が推論できない空リテラルやブロック越し代入には
  インライン型注釈(#: / @type var)を付ける
- File.write(Pathname, ...) → Pathname#write 等、
  rbs core の型が受けない等価な呼び出しを書き換える

挙動の変更はない(テスト 17589 件 green・rbs validate / rake sig 通過)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@znz znz merged commit 092218e into rurema:master Jul 11, 2026
9 checks passed
@znz znz deleted the rbs-markdown-sigs branch July 11, 2026 14:42
znz added a commit that referenced this pull request Jul 11, 2026
#231 で sig/ が lib/ の全宣言をカバーし steep check がエラー0・警告0に
なったので、退行を防ぐため CI に typecheck ジョブを追加する:

- rake rbs:install(rbs_collection.lock.yaml で固定された collection を取得)
- rake sig(rbs prototype → rbs subtract の残余ゼロ = sig 網羅の検査 + rbs validate)
- steep check

Ruby は最新安定版の 3.4 固定(バージョン網羅は build ジョブが担う)。
rbs / steep のバージョンは Gemfile.lock(rbs 3.10.3 / steep 1.9.4)で
再現される。

あわせて doctree と同様に、ドキュメント(doc/・README.md・ChangeLog)
だけの変更では既存ジョブ含め CI を回さないようにする。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant