Полный шаблон файла .cursorrules: готовые конфиги для Go, Python и TypeScript
Содержание гайда
По умолчанию редактор Cursor генерирует обобщенный код со стандартными библиотеками, часто предлагая устаревшие подходы или неподходящие паттерны. Чтобы заставить модель писать код строго в вашем корпоративном стиле, используется файл .cursorrules в корне проекта.
Ниже приведены готовые проверенные шаблоны конфигурации.
1. Конфиг для Go (Backend / Микросервисы)
Создайте файл .cursorrules в корне Go-проекта:
# Go Production Development Guidelines
You are an expert backend engineer writing modern Go (1.22+). Follow these rules strictly:
### 1. Code Style and Architecture
- Always follow standard Go project layout (`cmd/`, `internal/`, `pkg/`).
- Prefer standard library packages when possible.
- Never use panic() in production code. Always handle and return errors explicitly.
- Use structured logging via `log/slog`. Never use `fmt.Println` or the standard `log` package.
### 2. Error Handling
- Wrap errors using `fmt.Errorf("action description: %w", err)`.
- Use custom error types or sentinel errors with `errors.Is` and `errors.As`.
### 3. Concurrency and Context
- The first argument of all I/O or long-running functions must be `ctx context.Context`.
- Always respect `ctx.Done()` in goroutine loops to prevent leaks.
- Avoid global state; inject dependencies via constructors (`NewService(...)`).
### 4. Output Format
- Provide concise, production-ready code with complete error handling.
- Do not leave placeholder comments like `// implement this later`.
2. Конфиг для TypeScript & React (Frontend)
# Modern React & TypeScript Guidelines
You are an expert senior frontend engineer specializing in React 18+, Next.js (App Router), and Tailwind CSS.
### 1. Code Standards
- Always use TypeScript with strict typing. Never use `any`.
- Write functional components with explicit props interfaces: `interface Props { ... }`.
- Use server components by default in Next.js; add `'use client'` only when state or browser APIs are required.
### 2. State Management & Hooks
- Do not write massive useEffect hooks. Use React Query / TanStack Query for server state.
- Keep components small and modular (under 150 lines).
### 3. Styling
- Use Tailwind CSS utility classes exclusively.
- Do not create separate `.css` modules unless required for third-party libraries.
3. Конфиг для Python (FastAPI / Data)
# Python & FastAPI Production Standards
You are a senior Python architect writing modern Python 3.11+.
### 1. Type Hints & Pydantic
- All function arguments and return values must have explicit type annotations.
- Use Pydantic v2 models for request validation and response schemas.
### 2. Async & Architecture
- Use `async/await` for database queries and HTTP requests.
- Never block the event loop with synchronous I/O operations.
- Format code according to PEP 8 using Black and Ruff conventions.
Частые вопросы
❓ Видит ли Cursor правила во всех файлах проекта?
Да, инструкции из корневого файла .cursorrules автоматически добавляются в контекст каждого запроса Composer и чата.
❓ Тратятся ли токены на этот файл?
Файл занимает всего около 300 токенов, что абсолютно незаметно на лимитах контекста в 128k токенов.
❓ Можно ли совмещать несколько языков в одном файле?
Да, вы можете оформить правила отдельными блоками с заголовками для бэкенда и фронтенда.