mcpField
R
return-early-pattern

return-early-pattern

github.com/gkwa開発035 回インストール今日更新
リポジトリ

return-early-pattern について

return-early-patternは、主処理の前にガード節で失敗条件を処理するためのコーディングスキルです。複雑さを減らせる場合に限って適用し、明確な条件分岐は維持します。

主な機能

  1. 01ガード節で前提条件を処理
  2. 02主処理のネストを削減
  3. 03明確なif/else分岐を維持
  4. 04パターンの機械的な適用を回避

活用シーン

  1. 01nullチェックを含む関数の簡素化
  2. 02無効な引数を処理前に判定
  3. 03境界条件によるネストの削減

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/gkwa/volcanicviper --skill return-early-pattern

インストール後、Claude Code で/return-early-patternを入力して読み込まれたか確認します。

同梱ファイルtile.json

README(原文)English

プロジェクトの README より

この README の日本語訳はまだありません。以下は英語の原文です。日本語の紹介はページ上部をご覧ください。

Use guard clauses to handle edge cases and failure conditions at the top of a function. Return immediately rather than nesting the happy path inside conditionals.

Good:

function process(data):
    if data is null: return
    if not data.is_valid(): return
    return do_work(data)

Bad:

function process(data):
    if data is not null:
        if data.is_valid():
            return do_work(data)

Apply this pattern where it genuinely makes the code cleaner — functions with clear precondition checks (null references, invalid parameters, boundary conditions) followed by main business logic as the happy path.

Only apply where it reduces complexity. Preserve simple if/else structures where they are already clear. Do not force the pattern into short functions where a single if/else is more readable, or when conditions represent legitimate alternative behaviors rather than failure cases.

References:

コメント