Code Review Checklist 5 มิติ: Correctness, Security, Performance, Style, Test Coverage
พรอมต์สำหรับ developer ที่ต้องการ code review เชิงลึก ครอบคลุม 5 มิติหลัก พร้อมระบบ status icon และ verdict สรุป ช่วยให้ review ได้ครบถ้วนและสม่ำเสมอทุกครั้ง
## Code context
ฟังก์ชัน get_user() รับ user_id จาก HTTP request parameter แล้ว query ข้อมูลผู้ใช้จาก database เพื่อส่งคืนเป็น API response
## Code to review
```Python
def get_user(user_id):
query = "SELECT * FROM users WHERE id = " + user_id
result = db.execute(query)
print(f"Fetched user: {result[0]}")
return result[0]
```
## Review dimensions
### 1. Correctness
- Does the logic match the intended behaviour?
- Are edge cases handled (null, empty, overflow, off-by-one)?
- Are all error conditions caught and handled?
### 2. Security
- Is user input validated and sanitised before use?
- Are there injection risks (SQL, XSS, shell command)?
- Are secrets or sensitive data exposed in logs or responses?
- Are authentication and authorisation checks present where needed?
### 3. Performance
- Are there unnecessary loops, N+1 queries, or redundant computation?
- Is memory allocation proportionate to the task?
- Are expensive operations cached or deferred where appropriate?
### 4. Style & Readability
- Do names follow project conventions and clearly express intent?
- Are functions/classes small, single-purpose, and well-named?
- Is non-obvious logic accompanied by a brief comment?
### 5. Test Coverage
- Are unit tests present for the new or changed logic?
- Do tests cover both happy paths and edge/error cases?
- Are assertions specific and mocks meaningful?
## Output format
Return a Markdown report structured as:
- One H2 heading per dimension with an overall status icon
- Bullet-point findings (with ✅ / ⚠️ / ❌ prefix per item)
- A final **Verdict** section: `Approve` | `Request Changes` | `Reject` with a one-sentence rationale
ถ้าคำตอบยังกว้างไป พิมพ์บอกมันตรงๆ ว่าขอเจาะจงกว่านี้ ไม่ต้องเริ่มพรอมต์ใหม่
ปรับ 3 ช่องให้ตรงกับงานของคุณ
ภาษาโปรแกรมที่ใช้เขียนโค้ด เช่น Python, TypeScript, Go, Java
วางโค้ดที่ต้องการให้ review ทั้ง function หรือ class
อธิบายว่าโค้ดนี้ทำอะไร อยู่ใน context ไหน และ input มาจากไหน
ผลลัพธ์ที่จะได้
1. Correctness ⚠️
- ❌ ไม่มีการตรวจสอบว่า
resultว่างเปล่าก่อน accessresult[0]— จะเกิดIndexErrorหาก user ไม่พบใน database - ⚠️ ไม่มีการ validate ประเภทของ
user_idก่อนนำไปใช้ — หาก client ส่ง non-string มาอาจเกิด runtime error - ✅ Logic หลักของการ query ตรงกับ intent ที่ระบุใน context
2. Security ❌
- ❌ SQL Injection: ต่อ string โดยตรงด้วย
"SELECT * FROM users WHERE id = " + user_id— ต้องเปลี่ยนเป็น parameterised query เช่นdb.execute("SELECT * FROM users WHERE id = ?", (user_id,))โดยเด็ดขาด - ❌ Sensitive data leak:
print(f"Fetched user: {result[0]}")อาจ log ข้อมูล sensitive เช่น password hash หรือ PII ออก stdout/log file
ลองพรอมต์อื่นในแนวเดียวกัน
ดูพรอมต์ทั้งหมด
อธิบาย Legacy Code ให้ทีมใหม่เข้าใจเร็ว พร้อม Flag จุดเสี่ยงและ Tech Debt
ให้ AI วิเคราะห์โค้ดเก่าที่ซับซ้อน สรุปการทำงาน ชี้จุดเสี่ยง และจัดทำ tech debt log พร้อม effort estimate เพื่อให้ทีมใหม่เริ่มต้นได้อย่างปลอดภัยและมีทิศทางชัดเจน

สร้าง Test Cases ครอบคลุมจาก Function Spec
สร้าง test suite จาก function specification ที่ครอบคลุมทั้ง happy path, edge cases และ adversarial inputs พร้อม rationale ของแต่ละ test และ runnable code ในภาษาและ framework ที่เลือก ช่วย developer เขียน test อย่างเป็นระบบและตรวจจับ bug ที่ซ่อนอยู่ได้อย่างมีประสิทธิภาพ

เขียน Architecture Decision Record (ADR) สำหรับการตัดสินใจทางเทคนิค
สร้าง ADR ที่ครบถ้วนและอ่านง่าย บันทึกบริบท ตัวเลือกที่พิจารณา เหตุผลการตัดสินใจ และ trade-off ที่ยอมรับ ช่วยให้ทีมปัจจุบันและนักพัฒนารุ่นต่อไปเข้าใจว่าทำไมจึงตัดสินใจเช่นนั้น