# 查看代码

执行全面代码评审，并提供结构化反馈。

> \[!NOTE]
>
> * Copilot 提示文件为 公共预览版，可能随时更改。 提示文件仅适用于 VS Code、Visual Studio 和 JetBrains IDE。请查看 [关于自定义GitHub Copilot 响应](/zh/enterprise-cloud@latest/copilot/concepts/prompting/response-customization#about-prompt-files)。
> * 如需获取社区提供的有关特定语言和场景的提示文件示例，请参阅[出色的 GitHub Copilot 自定义内容](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md)仓库。

此提示文件执行全面的代码评审，并在 副驾驶聊天 中以一份综合报告的形式提供可执行的结构化反馈。

也可以在 Copilot 代码评审 中使用 Visual Studio Code，请参阅[使用 GitHub Copilot 代码审查](/zh/enterprise-cloud@latest/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=vscode)。 Copilot 代码评审 提供交互式的分步反馈，附带可直接应用的编辑器行内注释；而此提示文件提供包含教学说明的综合报告。

## 代码评审提示

```text copy
---
agent: 'agent'
description: 'Perform a comprehensive code review'
---

## Role

You're a senior software engineer conducting a thorough code review. Provide constructive, actionable feedback.

## Review Areas

Analyze the selected code for:

1. **Security Issues**
   - Input validation and sanitization
   - Authentication and authorization
   - Data exposure risks
   - Injection vulnerabilities

2. **Performance & Efficiency**
   - Algorithm complexity
   - Memory usage patterns
   - Database query optimization
   - Unnecessary computations

3. **Code Quality**
   - Readability and maintainability
   - Proper naming conventions
   - Function/class size and responsibility
   - Code duplication

4. **Architecture & Design**
   - Design pattern usage
   - Separation of concerns
   - Dependency management
   - Error handling strategy

5. **Testing & Documentation**
   - Test coverage and quality
   - Documentation completeness
   - Comment clarity and necessity

## Output Format

Provide feedback as:

**🔴 Critical Issues** - Must fix before merge
**🟡 Suggestions** - Improvements to consider
**✅ Good Practices** - What's done well

For each issue:
- Specific line references
- Clear explanation of the problem
- Suggested solution with code example
- Rationale for the change

Focus on: ${input:focus:Any specific areas to emphasize in the review?}

Be constructive and educational in your feedback.
```

## 如何使用此提示文件

1. 将上述内容另存为 `review-code.prompt.md`，并将其保存在 `.github/prompts` 文件夹中。
2. 在编辑器中打开要评审的代码文件。
3. 在 Visual Studio Code 中，显示 副驾驶聊天 视图，并输入 `/review-code` 以使用此提示文件触发自定义评审。 （可选）也可以通过键入 `focus=security` 等内容，来指明希望重点评审的方面。

## 其他阅读材料

* Visual Studio Code 文档中的[使用 Visual Studio Code 中的提示文件](https://code.visualstudio.com/docs/copilot/customization/prompt-files) - 有关如何创建和使用提示文件的信息
* [关于自定义GitHub Copilot 响应](/zh/enterprise-cloud@latest/copilot/concepts/response-customization) - GitHub Copilot 中的响应自定义概述
* [出色的 GitHub Copilot 自定义内容](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md) - 社区提供的自定义提示文件的仓库以及特定语言和场景的其他自定义内容