実際に私が使っているルール
Cursorには基本的に英文で指示を出すことを推奨します。ただし、英語で記述しても回答を日本語に指定することができます。
以下は英語版のルール設定例です。AI モデルには英語版の方がより正確に指示が伝わる可能性が高いです。
# Python & TypeScript スタック向け Cursor Rules (英語版)
## General Coding Guidelines
- Follow clean code principles across all languages
- Use descriptive variable names that explain their purpose
- Comment complex logic or business rules
- Follow DRY (Don't Repeat Yourself) principles
- Write unit tests for all core functionality
## Python Guidelines
- Follow PEP 8 style guidelines
- Use type hints for function parameters and return values
- Prefer list/dict comprehensions over loops when appropriate
- Document functions with docstrings using Google or NumPy style
- Use meaningful exception handling with specific exception types
- Structure projects with clear module organization
## TypeScript/Next.js Guidelines
- Use Next.js 14.2.23 with App Router architecture
- Organize code by features or domains rather than by file types
- Leverage TypeScript's type system fully - avoid using 'any' type
- Follow the official Next.js patterns for data fetching and routing
### Component Structure
- Use functional components with hooks
- Separate UI components from logic/data-fetching components
- Create reusable components in a shared component library
- Follow component naming convention: `ComponentName/index.tsx` with optional `ComponentName/ComponentName.module.css`
### Styling
- Use Tailwind CSS for styling following utility-first approach
- Group Tailwind classes logically: layout, sizing, typography, colors
- IMPORTANT: Avoid using Grid components directly - use Box components instead for layouts
- For complex UI components, use either MUI or Headless UI (prefer Headless UI for better UX)
### Form Handling
- Use React Hook Form for all form implementations
- Implement validation schemas with Zod
- Structure form validations consistently
- Handle form errors with clear user feedback
### State Management
- Use Zustand for global state management
- Keep state minimal and focused
- Split stores by domain when appropriate
- Use React Query for server state management
### Performance Considerations
- Implement proper code-splitting with Next.js
- Use Next.js Image component for optimized images
- Properly memoize components and callbacks where appropriate
- Implement proper loading states and error boundaries
## Response Preferences
- Provide detailed explanations for any implementation decisions
- When suggesting improvements, explain the reasoning
- Always include code examples when explaining concepts
- Respond in Japanese with UTF-8 encoding
以下は上記の英語版を日本語版に変換したものです。日本人が内容を理解しやすくなっています。
# Python & TypeScript スタック向け Cursor Rules (日本語版)
## 一般的なコーディングガイドライン
- すべての言語でクリーンコードの原則に従う
- 変数名は目的を説明する説明的な名前を使用する
- 複雑なロジックやビジネスルールにはコメントを付ける
- DRY(同じことを繰り返さない)原則に従う
- すべての主要機能に単体テストを書く
## Pythonガイドライン
- PEP 8スタイルガイドラインに従う
- 関数のパラメータと戻り値に型ヒントを使用する
- 適切な場合はループよりリスト/辞書内包表記を優先する
- GoogleまたはNumPyスタイルを使用して関数をdocstringsでドキュメント化する
- 特定の例外タイプを使用した意味のある例外処理を実装する
- 明確なモジュール構成でプロジェクトを構造化する
## TypeScript/Next.jsガイドライン
- Next.js 14.2.23(App Router)アーキテクチャを使用する
- ファイルタイプではなく、機能やドメインでコードを整理する
- TypeScriptの型システムを最大限に活用し、'any'型の使用を避ける
- データフェッチングとルーティングには公式のNext.jsパターンに従う
### コンポーネント構造
- フック付きの関数コンポーネントを使用する
- UIコンポーネントとロジック/データフェッチングコンポーネントを分離する
- 共有コンポーネントライブラリで再利用可能なコンポーネントを作成する
- コンポーネント命名規則に従う:`ComponentName/index.tsx`(オプションで`ComponentName/ComponentName.module.css`)
### スタイリング
- ユーティリティファーストアプローチでTailwind CSSを使用する
- Tailwindクラスを論理的にグループ化:レイアウト、サイズ調整、タイポグラフィ、色
- 重要:Gridコンポーネントを直接使用せず、代わりにレイアウトにはBoxコンポーネントを使用する
- 複雑なUIコンポーネントには、MUIまたはHeadless UI(より良いUXにはHeadless UIを推奨)を使用する
### フォーム処理
- すべてのフォーム実装にはReact Hook Formを使用する
- Zodでバリデーションスキーマを実装する
- フォームバリデーションを一貫した構造で実装する
- 明確なユーザーフィードバックでフォームエラーを処理する
### 状態管理
- グローバル状態管理にはZustandを使用する
- 状態は最小限かつ焦点を絞ったものにする
- 適切な場合はドメインごとにストアを分割する
- サーバー状態管理にはReact Queryを使用する
### パフォーマンスの考慮事項
- Next.jsで適切なコード分割を実装する
- 最適化された画像にはNext.js Imageコンポーネントを使用する
- 適切な場所でコンポーネントとコールバックをメモ化する
- 適切なローディング状態とエラー境界を実装する
## 応答の設定
- 実装の決定に関する詳細な説明を提供する
- 改善案を提案する際は、理由を説明する
- 概念を説明する際は常にコード例を含める
- 日本語(UTF-8エンコーディング)で応答する
よくある質問
Q: Cursor Rulesが効かない場合はどうすればいいですか?
A: まず、User RulesやProject Rulesが正しく設定されているか確認し、Cursorを再起動してください。それでも解決しない場合は、ルールの構文が正しいか、競合するルールがないかを確認してみてください。
Q: User Rulesを更新するにはどうすればいいですか?
A: Cursor Settings > Rules > User Rulesからルールを直接修正し、保存するだけです。
Q: 日本語化はどのように行いますか?
A: コマンドパレット(F1キー)を開き、「Configure Display Language」を選択し、日本語を選択します。Cursorを再起動すると反映されます。
Q: 複数のプロジェクトで異なるルールを適用するにはどうすればいいですか?
A: 各プロジェクトを個別のウィンドウで開くか、異なるワークスペースに配置することで、それぞれのProject Rulesが適切に適用されます。