copilot-docs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Copilot Custom Instructions

GitHub Copilot 自定义指令

Configure repository-specific instructions for GitHub Copilot.
为GitHub Copilot配置仓库专属的指令。

Quick Start

快速开始

Create
.github/copilot-instructions.md
in your repository:
markdown
undefined
在你的仓库中创建
.github/copilot-instructions.md
文件:
markdown
undefined

Copilot Instructions

Copilot Instructions

Code Style

Code Style

  • Use TypeScript with strict mode
  • Prefer functional components with hooks
  • Use Tailwind CSS for styling
  • Use TypeScript with strict mode
  • Prefer functional components with hooks
  • Use Tailwind CSS for styling

Project Context

Project Context

This is a Next.js 14 app using the App Router. API routes are in
app/api/
.
undefined
This is a Next.js 14 app using the App Router. API routes are in
app/api/
.
undefined

Effective Patterns

实用模式

Project Context

项目上下文

markdown
undefined
markdown
undefined

Project Context

Project Context

Tech Stack

Tech Stack

  • Next.js 14 with App Router
  • TypeScript 5.3+
  • Tailwind CSS 3.4
  • Prisma ORM with PostgreSQL
  • Next.js 14 with App Router
  • TypeScript 5.3+
  • Tailwind CSS 3.4
  • Prisma ORM with PostgreSQL

Architecture

Architecture

  • app/
    - Next.js App Router pages and API routes
  • components/
    - React components
  • lib/
    - Utility functions and shared code
  • prisma/
    - Database schema and migrations
undefined
  • app/
    - Next.js App Router pages and API routes
  • components/
    - React components
  • lib/
    - Utility functions and shared code
  • prisma/
    - Database schema and migrations
undefined

Code Standards

代码规范

markdown
undefined
markdown
undefined

Code Standards

Code Standards

TypeScript

TypeScript

  • Enable strict mode
  • Prefer
    interface
    over
    type
    for object shapes
  • Use explicit return types on functions
  • Enable strict mode
  • Prefer
    interface
    over
    type
    for object shapes
  • Use explicit return types on functions

React

React

  • Use functional components exclusively
  • Prefer named exports
  • Extract hooks to
    hooks/
    directory
  • Use functional components exclusively
  • Prefer named exports
  • Extract hooks to
    hooks/
    directory

Error Handling

Error Handling

  • Use Result pattern for fallible operations
  • Always handle async errors with try/catch
  • Log errors with structured format
undefined
  • Use Result pattern for fallible operations
  • Always handle async errors with try/catch
  • Log errors with structured format
undefined

Naming Conventions

命名规范

markdown
undefined
markdown
undefined

Naming Conventions

Naming Conventions

Files

Files

  • Components: PascalCase (Button.tsx)
  • Utilities: camelCase (formatDate.ts)
  • Constants: SCREAMING_SNAKE_CASE
  • Components: PascalCase (Button.tsx)
  • Utilities: camelCase (formatDate.ts)
  • Constants: SCREAMING_SNAKE_CASE

Code

Code

  • Boolean variables: is*, has*, should* prefix
  • Event handlers: handle* prefix (handleClick)
  • Async functions: *Async suffix
undefined
  • Boolean variables: is*, has*, should* prefix
  • Event handlers: handle* prefix (handleClick)
  • Async functions: *Async suffix
undefined

Testing

测试指南

markdown
undefined
markdown
undefined

Testing Guidelines

Testing Guidelines

Unit Tests

Unit Tests

  • Use Vitest for unit testing
  • Place tests next to source files (*.test.ts)
  • Mock external dependencies
  • Use Vitest for unit testing
  • Place tests next to source files (*.test.ts)
  • Mock external dependencies

Test Patterns

Test Patterns

typescript
describe('Component', () => {
  it('should render correctly', () => {
    // Arrange, Act, Assert pattern
  });
});
undefined
typescript
describe('Component', () => {
  it('should render correctly', () => {
    // Arrange, Act, Assert pattern
  });
});
undefined

API Patterns

API模式

markdown
undefined
markdown
undefined

API Patterns

API Patterns

Route Handlers

Route Handlers

typescript
// Standard response format
return NextResponse.json({
  data: result,
  error: null,
  meta: { timestamp: Date.now() }
});

// Error response
return NextResponse.json(
  { data: null, error: { code: 'NOT_FOUND', message: '...' } },
  { status: 404 }
);
typescript
// Standard response format
return NextResponse.json({
  data: result,
  error: null,
  meta: { timestamp: Date.now() }
});

// Error response
return NextResponse.json(
  { data: null, error: { code: 'NOT_FOUND', message: '...' } },
  { status: 404 }
);

Validation

Validation

  • Use Zod for request validation
  • Validate early, fail fast
undefined
  • Use Zod for request validation
  • Validate early, fail fast
undefined

Do's and Don'ts

注意事项(可做/不可做)

markdown
undefined
markdown
undefined

Guidelines

Guidelines

Do

Do

  • Write self-documenting code
  • Add JSDoc comments for public APIs
  • Use meaningful variable names
  • Write self-documenting code
  • Add JSDoc comments for public APIs
  • Use meaningful variable names

Don't

Don't

  • Use
    any
    type
  • Leave console.log in production code
  • Commit sensitive data
undefined
  • Use
    any
    type
  • Leave console.log in production code
  • Commit sensitive data
undefined

File Location

文件位置

The file must be at
.github/copilot-instructions.md
(not in root).
该文件必须放置在
.github/copilot-instructions.md
路径下(不能在根目录)。

Resources

参考资源