Skill 详情
cursor-rules-config
Explains Cursor project-rule configuration, adjacent but not Claude skills installation.
使用前先检查
自动化审核只检查相关性,不代表安全审查或推荐。使用前请阅读来源中的说明。
SKILL.md
这段内容是审核时保存的快照。外部来源才是完整且最新的版本。
--- name: cursor-rules-config description: 'Configure Cursor project rules using .cursor/rules/*.mdc files and legacy .cursorrules. Triggers on "cursorrules", ".cursorrules", "cursor rules", "cursor config", "cursor project settings", ".mdc rules", "project rules". ' allowed-tools: Read, Write, Edit, Bash(cmd:*) version: 1.18.0 license: MIT author: Jeremy Longshore <[email protected]> tags: - saas - cursor - cursor-rules compatibility: Designed for Claude Code, also compatible with Codex and OpenClaw --- # Cursor Rules Config Configure project-specific AI behavior through Cursor's rules system. The modern approach uses `.cursor/rules/*.mdc` files; the legacy `.cursorrules` file is still supported but deprecated. ## Rules System Architecture ### Modern Project Rules (.cursor/rules/*.mdc) Each `.mdc` file contains YAML frontmatter followed by markdown content: ```yaml --- description: "Enforce TypeScript strict mode and functional patterns" globs: "src/**/*.ts,src/**/*.tsx" alwaysApply: false --- # TypeScript Standards - Use `const` over `let`, never `var` - Prefer pure functions over classes - All functions must have explicit return types - Use discriminated unions over enums ``` **Frontmatter fields:** | Field | Type | Purpose | |-------|------|---------| | `description` | string | Concise rule purpose (shown in Cursor UI) | | `globs` | string | Gitignore-style patterns for auto-attachment | | `alwaysApply` | boolean | `true` = always active; `false` = only when matching files referenced | ### Rule Types by `alwaysApply` + `globs` Combination | alwaysApply | globs | Behavior | |-------------|-------|----------| | `true` | empty | Always injected into every prompt | | `false` | set | Auto-attached when matching files are in context | | `false` | empty | Manual only -- reference with `@Cursor Rules` in chat | ### File Naming Convention Use kebab-case with `.mdc` extension. Names should describe the rule's scope: ``` .cursor/rules/ typescript-standards.mdc react-component-patterns.mdc api-error-handling.mdc testing-conventions.mdc database-migrations.mdc security-requirements.mdc ``` Create new rules via: `Cmd+Shift+P` > `New Cursor Rule` ### Complete Project Rules Example **`.cursor/rules/project-context.mdc`** (always-on): ```yaml --- description: "Core project context and conventions" globs: "" alwaysApply: true --- # Project: E-Commerce Platform Tech stack: Next.js 15, TypeScript 5.7, Prisma ORM, PostgreSQL, Tailwind CSS 4. Package manager: pnpm. Monorepo with turborepo. ## Conventions - API routes in `app/api/` using Route Handlers - Server Components by default, `"use client"` only when needed - Error boundaries at layout level - All monetary values stored as integers (cents) - Dates stored as UTC, displayed in user timezone ``` **`.cursor/rules/react-patterns.mdc`** (glob-scoped): ```yaml --- description: "React component standards for TSX files" globs: "src/**/*.tsx,app/**/*.tsx" alwaysApply: false --- # React Component Rules - Export components as named exports, not default - Props interface named `{Component}Props` - Use `forwardRef` for components accepting `ref` - Colocate styles in `.module.css` files - Server Components: no `useState`, `useEffect`, or event handlers ```tsx // Correct pattern export interface ButtonProps { variant: 'primary' | 'secondary'; children: React.ReactNode; onClick?: () => void; } export function Button({ variant, children, onClick }: ButtonProps) { return ( <button className={styles[variant]} onClick={onClick}> {children} </button> ); } ``` ``` **`.cursor/rules/api-routes.mdc`** (glob-scoped): ```yaml --- description: "API route handler patterns" globs: "app/api/**/*.ts" alwaysApply: false --- # API Route Standards - Always validate request body with Zod - Return typed `NextResponse.json()` responses - Use consistent error response shape: `{ error: string, code: string }` - Wrap handlers in try/catch with struc在 GitHub 阅读完整来源 (打开外部页面)