Files
affaan-m--everything-claude…/docs/ja-JP/rules/ruby/coding-style.md
T
wehub-resource-sync d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:55 +08:00

47 lines
2.8 KiB
Markdown

---
paths:
- "**/*.rb"
- "**/*.rake"
- "**/Gemfile"
- "**/*.gemspec"
- "**/config.ru"
---
# Ruby コーディングスタイル
> このファイルは [common/coding-style.md](../common/coding-style.md) を Ruby および Rails 固有のコンテンツで拡張します。
## 標準
- プロジェクトが既に古いサポート対象ランタイムを固定していない限り、新しい Rails 開発では **Ruby 3.3+** をターゲットにする。
- 本番環境では起動時間、メモリ、リクエスト/ジョブのスループットを測定した後にのみ **YJIT** を有効にする。
- プロジェクトがその規約を使用している場合、新しい Ruby ファイルに `# frozen_string_literal: true` を追加する。
- 巧妙なメタプログラミングよりも明快な Ruby を優先する。DSL を多用するコードは狭く、テストされた境界の背後に隔離する。
## フォーマットとリンティング
- プロジェクトのチェックイン済み RuboCop 設定を使用する。Rails 8+ アプリでは `rubocop-rails-omakase` から始め、コードベースに実際の規約がある場合にのみカスタマイズする。
- フォーマッタ/リンターのコマンドは binstub またはスクリプトの背後に配置し、CI とローカルの実行を一致させる:
```bash
bundle exec rubocop
bundle exec rubocop -A
```
- 例外が狭く、文書化されており、コードで明確に表現するのが困難でない限り、インラインで cop を無効にしない。
## Rails スタイル
- カスタム構造を追加する前に、Rails の命名規則とディレクトリ規約に従う。
- コントローラはトランスポートに焦点を当てる: 認証、認可、パラメータ処理、レスポンスの形状。
- 再利用可能なドメインロジックは、デフォルトの儀式としてではなく、実際の複雑さに基づいてモデル、concerns、サービスオブジェクト、クエリオブジェクト、またはフォームオブジェクトに配置する。
- グローバルにインストールされたコマンドよりも `bin/rails``bin/rake`、およびチェックイン済み binstub を優先する。
## エラーハンドリング
- 特定の例外を rescue する。広範な `rescue StandardError` ブロックは、再スローするか、運用者に十分なコンテキストを保持する場合を除いて避ける。
- 運用イベントには `ActiveSupport::Notifications` またはアプリのロガーを使用する。コミット済みのアプリケーションコードに `puts``pp``debugger` を残さない。
## 参考
サービス/リポジトリの階層化ガイダンスについてはスキル: `backend-patterns` を参照。