refactor(preferences): tabBehavior/arrowBehaviorの検証をsatisfies由来のヘルパーに統合#75
Merged
Conversation
loadPreferencesはtabBehavior/arrowBehaviorの許容リテラルを`===`チェーンで 独自に列挙しており、EditorPreferencesの型定義と手動同期する必要があった。 メンバーを追加してもここは無言でコンパイルが通り、新しい値がlocalStorage から黙って握りつぶされ続ける穴になっていた(#69でmodel.tsのNodeType/ NumFormatに対して塞いだのと同じ穴)。 isTabBehavior/isArrowBehaviorを追加し、`as const satisfies Record<...>`で 型からメンバー漏れ・過不足をコンパイルエラーにする。loadPreferencesは その判定関数を呼ぶだけにした。挙動は変えていない。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ExGyoV6xYJdhe8QHEfSsnG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
観測した問題
editorPreferences.tsのloadPreferencesはtabBehavior/arrowBehaviorの許容リテラルを===チェーンで独自に列挙して判定しており、EditorPreferencesの型定義と手動同期する必要がありました。このため、将来
tabBehavior/arrowBehaviorにメンバーを追加しても、この検証コードは無言でコンパイルが通ってしまいます。新しい値は localStorage から読み込まれるたびに黙って握りつぶされ、常にデフォルト値へフォールバックし続けるバグの温床でした。同じ穴は以前
domain/model.tsのNodeType/NumFormatにもあり、#69 (refactor(model): NodeType/NumFormatの検証をsatisfies由来のヘルパーに統合) でisStoredNodeType/isNumFormatというas const satisfies Record<...>ベースのヘルパーに置き換えて塞いでいます。editorPreferences.tsは同じリファクタが適用されないまま残っていました。変更内容
STORED_NODE_TYPE_SET/isStoredNodeTypeと同じ手筋で、TAB_BEHAVIOR_SET/isTabBehavior、ARROW_BEHAVIOR_SET/isArrowBehaviorを追加しました。loadPreferencesはこの判定関数を呼ぶだけにしました。挙動は変えていません。守りたい設計意図
NodeType/NumFormatと同じ形でeditorPreferences.tsにも適用する。確認方法
npx tsc --noEmit -p tsconfig.json— 型エラーなしpnpm test(app/application/editorPreferences.test.ts) — 既存のフォールバック挙動テストが全てパス。加えてtabBehavior/arrowBehaviorの全リテラルを型で列挙して round-trip する回帰テストを追加(メンバーの typo/rename があればテストがコンパイルエラーになる)。TAB_BEHAVIOR_SET/ARROW_BEHAVIOR_SETから意図的に1メンバーを削除するとsatisfies Record<...>の型エラーが発生することを確認済み(コミットには含めていません)。レビュー観点
TAB_BEHAVIOR_SET/ARROW_BEHAVIOR_SETのキーがEditorPreferencesの型と一致しているか(satisfiesが保証するので実質コンパイラ任せで良い)。loadPreferencesの分岐ロジック自体は変更していないこと(振る舞いの同一性)。🤖 Generated with Claude Code
https://claude.ai/code/session_01ExGyoV6xYJdhe8QHEfSsnG
Generated by Claude Code