这是 Cursor 实战指南系列的最后一篇,讲一个很多人会忽略但极其有用的场景:用 AI 做代码审查。
传统 Code Review 的痛点:
AI review 解决了其中两个问题:随时可做、不会敷衍。
AI 不会因为今天心情不好就跳过 review,也不会因为代码是老板写的就不提意见。
Cursor 内置了 Git 支持,可以直接看到文件的 diff 变化。
在 Chat 面板里,Cursor 能自动识别当前你在看哪个文件的改动。结合 @ 引用,可以精准地问 AI:"这个改动有什么问题?"
第一步:打开要 review 的文件
在 Cursor 中打开 Git diff 视图,或者直接打开你想 review 的文件。
第二步:@文件问 AI
在 Chat 面板输入:
@src/components/UserProfile.tsx
Review this component for:
1. Potential bugs
2. Security issues
3. Performance problems
4. Code style inconsistencies
第三步:逐条处理 AI 的反馈
AI 会列出具体问题,每个问题都指向具体行。Cursor 可以直接从 AI 的回复跳转到对应代码行,查看上下文。
第四步:用 Apply 修复
如果 AI 的修复建议合理,直接点 Apply,一键应用。
以下提示词可以直接用:
@[文件名]
Review for bugs:
- Null/undefined checks
- Error handling
- Async race conditions
- Memory leaks
@[文件名]
Security review:
- SQL injection
- XSS vulnerabilities
- Insecure API calls
- Exposed credentials or keys
@[文件名]
Performance review:
- Unnecessary re-renders
- Expensive operations in loops
- Missing memoization
- Large data without pagination
@[文件名]
Architecture review:
- Does this follow the project's patterns?
- Is the separation of concerns respected?
- Any code that will be hard to maintain?
Cursor 本地 review 很强,但 GitHub PR 流程通常在线上。可以这样组合:
这样 human reviewer 的时间用在刀刃上,而不是花半小时找格式问题。
AI review 不是万能的,有几件事它做不到:
最佳实践:AI review 替代不了 human review,但能大幅减少 human reviewer 的工作量。AI 过滤掉明显的 bug、格式问题、安全漏洞,human reviewer 专注在业务价值上。
7 篇文章,我们覆盖了:
Cursor 不是一个普通的代码补全工具——它是一套 AI 原生的开发工作流。把这 7 个功能组合起来用,效率提升会非常明显。
建议:从中选 2-3 个你最常用的功能先用起来,熟悉之后再扩展到其他场景。
Cursor AI编辑器实战指南系列,全部完结。感谢阅读。
评论区