add: グローバル Rust 言語ルール (Result/thiserror/clippy)#289
Open
shunsock wants to merge 1 commit into
Open
Conversation
エラーを Result/Option の型で表現すること、anyhow を禁止し thiserror ADT でエラー型を定義すること、clippy で機械検証することの 3 規律を language__rust.md として明文化する。既存の language__hcl.md と同じ 配置・骨格に揃え、configs/claude/rules/ 配下に置くことで Nix の home.file.".claude/rules" 経由で自動配布される。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
configs/claude/rules/language__rust.mdを新規追加unwrap()/expect()/panic!()を production コードで禁止、Result<T, E>/Option<T>で失敗パスを露出thiserror::Error+ enum で定義、anyhow::Error/Box<dyn Error>は禁止、#[from]で透過変換[workspace.lints.clippy]にunwrap_used/expect_used/panicをwarnで設定し、CI では-D warningsで落とすMotivation
shunsock/playground の Inazuma プロジェクト (Effect-Based + 4-Layer DDD の Rust CLI) で「エラーは型で表現する」規律がドキュメント化されていないことがレビューで指摘された。これは Inazuma 固有の規律ではなく Rust プロジェクト全般に適用したいので、Inazuma 側ではなく dotfiles の
configs/claude/rules/に置くことで、~/.claude/rules/にグローバル配布する。既存の
language__hcl.mdと同じ骨格 (規律 → 守ること → コード例 → 理由) で揃えた。Nix のhome.file.".claude/rules".source = ../../configs/claude/rulesでディレクトリ単位で配布されているため、新規ファイル追加のみで自動配布される (nix-darwin/nix-os両方のmodules/claude.nixに変更不要)。Defaults Assumed (auto mode)
ヒアリング論点について auto mode 下で以下を採用:
warn(CI で警告を出すが即落としはしない、段階導入しやすい)#[cfg(test)]配下のunwrap/assert!は規律の対象外と明記anyhowのみ (要件の主旨に沿う最小)clone多用や#[non_exhaustive]等は今回見送り合わない箇所があれば追加コミットで調整可能。
Verification
nix flake check(nix-darwin): passednix build .#darwinConfigurations.shunsock-darwin.system: main ブランチでもdarwin.apple_sdk_11_0 has been removedで失敗 (本 PR 由来ではない既知の依存問題)configs/claude/rules/配下の Markdown 1 ファイル追加のみで、Nix の評価結果に影響しないことを確認 (home.fileの source はディレクトリ参照のため)🤖 Generated with Claude Code