Summary
「Parse, don't validate」原則に基づくコードレビューと設計支援。validateパターン(チェックして結果を捨てる) をparseパターン(チェック結果を型で保持)に変換し、型システムで不変式を強制する設計を促進する。…
j5ik2o/okite-ai
>- 「Parse, don't validate」原則に基づくコードレビューと設計支援。validateパターン(チェックして結果を捨てる) をparseパターン(チェック結果を型で保持)に変換し、型システムで不変式を強制する設計を促進する。 コードレビュー、新規実? 対象言語: Rust, Haskell, TypeScript, Scala, Java, Go, Python。 トリガー:「バリデーションを改善して」「型で保証したい」「shotgun parsingを直して」 「不正な状?
npx skills add j5ik2o/okite-ai --skill parse-dont-validate
「Parse, don't validate」原則に基づくコードレビューと設計支援。validateパターン(チェックして結果を捨てる) をparseパターン(チェック結果を型で保持)に変換し、型システムで不変式を強制する設計を促進する。…
Related neighbors and high-traction skills in the same topics — useful to compare before installing.
Pre-deployment validation for Azure readiness. Run deep checks on configuration, infrastructure…
567.7K installsValidates skills in this repo against agentskills.io spec and Claude Code best practices. Use v…
6.2K installsQA an analysis before sharing -- methodology, accuracy, and bias checks. Use when reviewing an …
3.2K installsRun `tao-daft validate` to check NVIDIA TAO DAFT datasets for structure, schema, and cross-refe…
1.5K installs>- Use after jetson-flash-image to run static BSP checks, on-target smoke/regression tests on a…
1.1K installsValidate that a branch or pull request implementation matches introduced product, technical, se…
21K installsOther skills from j5ik2o/okite-ai · top by installs.
npx skills add j5ik2o/okite-ai
Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.
main
Files included with this skill beyond the listing page.
SKILL.md
5,086 B
SUMMARY.md
754 B
情報を捨てるvalidationから、情報を保持するparsingへ変換する。
チェック結果を捨てずに型で保持する。
| アプローチ | 戻り値 | 情報 | 問題 |
|---|---|---|---|
| Validate | () / void / bool |
捨てる | 再チェック必要、型が保証しない |
| Parse | 型付き値 | 保持 | 一度のチェックで済む、型が保証 |
チェック関数を書こうとしている
↓
戻り値は何か?
├─ () / void / bool → Validateパターン(問題あり)
└─ 新しい型 → Parseパターン(推奨)
以下のパターンを見つけたら変換を検討:
❌ validate*() → ()
❌ check*() → bool
❌ assert*() → ()(表明目的以外)
❌ is*() → bool(分岐後に同じ値を使う場合)
❌ "should never happen" コメント
❌ case None/null の after 正常ケース
// ❌ Validate: 情報を捨てる
function validateNonEmpty(list: string[]): void {
if (list.length === 0) throw new Error("list cannot be empty");
}
// ✅ Parse: 情報を保持する
type NonEmptyArray<T> = [T, ...T[]];
function parseNonEmpty<T>(list: T[]): NonEmptyArray<T> {
if (list.length === 0) throw new Error("list cannot be empty");
return list as NonEmptyArray<T>;
}
// ❌ Validate: チェックして捨てる
function checkNoDuplicateKeys(pairs: [string, unknown][]): void {
const seen = new Set<string>();
for (const [key] of pairs) {
if (seen.has(key)) throw new Error(`duplicate key: ${key}`);
seen.add(key);
}
}
// ✅ Parse: Mapに変換して保持
function parseToMap(pairs: [string, unknown][]): Map<string, unknown> {
const result = new Map<string, unknown>();
for (const [key, value] of pairs) {
if (result.has(key)) throw new Error(`duplicate key: ${key}`);
result.set(key, value);
}
return result;
}
// ❌ 外部から直接構築可能
pub struct Email(String);
// ✅ Parse: Smart constructorで検証済みを保証
mod email {
pub struct Email(String); // private field
impl Email {
pub fn parse(s: &str) -> Result<Self, ParseError> {
if s.contains('@') && s.len() > 3 {
Ok(Email(s.to_string()))
} else {
Err(ParseError::InvalidEmail)
}
}
pub fn as_str(&self) -> &str { &self.0 }
}
}
避けるべき: 入力検証がコード全体に散らばるパターン。
❌ 処理開始 → 部分処理 → 検証失敗 → ロールバック困難
✅ 境界で完全Parse → 処理は型を信頼 → 安全
Maybe/Optionが頻出する箇所error "impossible"だけなら改修コスト大コードレビュー時の確認ポイント:
void/()を返す検証関数はないか言語別の実装パターン、型設計の詳細は [references/patterns.md](references/patterns.md) を参照。
このスキルを使用する際は、以下のスキルも併せて参照すること:
domain-primitives-and-always-valid: スマートコンストラクタによるドメインプリミティブの設計when-to-wrap-primitives: プリミティブ型をラップすべきかの判断基準domain-building-blocks: 値オブジェクトの設計(parseパターンの適用先)