Claude Code के साथ Code Review Checklist
Code quality सुधारने के लिए Claude Code का उपयोग करके practical code review checklist।
Claude Code से Code Review को कुशल बनाएं
Code review quality maintain करने के लिए एक महत्वपूर्ण process है, लेकिन reviewer पर बोझ बड़ा होता है। Claude Code का उपयोग करके, व्यवस्थित checklist पर आधारित efficient review संभव है।
Security Check
> इस PR के code को security की नज़र से review करो।
> XSS, SQL injection, authentication vulnerabilities check करो।
// Security checklist
const securityChecks = {
// 1. Input validation
inputValidation: {
check: 'User input sanitize हो रहा है या नहीं',
bad: `element.innerHTML = userInput;`,
good: `element.textContent = userInput;`,
},
// 2. SQL Injection
sqlInjection: {
check: 'Parameterized query use हो रहा है या नहीं',
bad: `db.query(\`SELECT * FROM users WHERE id = \${userId}\`);`,
good: `db.query('SELECT * FROM users WHERE id = ?', [userId]);`,
},
// 3. Authentication/Authorization
auth: {
check: 'API endpoint पर authentication middleware है या नहीं',
bad: `app.get('/api/admin/users', handler);`,
good: `app.get('/api/admin/users', requireAuth, requireAdmin, handler);`,
},
// 4. Secret information exposure
secrets: {
check: 'Environment variables client को leak नहीं हो रहे',
bad: `const apiKey = "sk-1234567890abcdef";`,
good: `const apiKey = process.env.API_KEY;`,
},
};
Performance Check
// Performance checklist
const performanceChecks = [
{
item: 'N+1 query तो नहीं हो रहा',
bad: `
const users = await db.user.findMany();
for (const user of users) {
const posts = await db.post.findMany({ where: { userId: user.id } });
}`,
good: `
const users = await db.user.findMany({
include: { posts: true },
});`,
},
{
item: 'अनावश्यक re-render तो नहीं हो रहा',
bad: `
function Component() {
const handler = () => doSomething();
return <Child onClick={handler} />;
}`,
good: `
function Component() {
const handler = useCallback(() => doSomething(), []);
return <Child onClick={handler} />;
}`,
},
{
item: 'बड़ी list में virtualization लागू है या नहीं',
check: '1000+ items की list → react-virtual पर विचार करें',
},
];
Readability/Maintainability Check
> इस code की readability improve करने के suggestions दो।
> Naming conventions, function length, comments की appropriateness check करो।
// Readability check points
// 1. Function की length (30 lines से कम ideal)
// ❌ एक function में सारी processing
async function processOrder(order: Order) {
// 100 lines की processing...
}
// ✅ Responsibility के अनुसार split
async function processOrder(order: Order) {
const validated = validateOrder(order);
const priced = calculateTotal(validated);
const payment = await processPayment(priced);
return createConfirmation(payment);
}
// 2. Early return pattern
// ❌ Deep nesting
function getDiscount(user: User) {
if (user) {
if (user.isPremium) {
if (user.orders > 10) {
return 0.2;
}
return 0.1;
}
return 0.05;
}
return 0;
}
// ✅ Early return
function getDiscount(user: User) {
if (!user) return 0;
if (!user.isPremium) return 0.05;
if (user.orders > 10) return 0.2;
return 0.1;
}
// 3. Magic numbers हटाएं
// ❌
if (status === 3) { /* ... */ }
// ✅
const ORDER_STATUS = { PENDING: 1, PROCESSING: 2, COMPLETED: 3 } as const;
if (status === ORDER_STATUS.COMPLETED) { /* ... */ }
Error Handling Check
// Error handling check points
// ❌ Error को swallow करना
try {
await saveData(data);
} catch (e) {
// कुछ नहीं करना
}
// ✅ Proper error handling
try {
await saveData(data);
} catch (error) {
logger.error('Data save fail हुआ', { error, data: data.id });
throw new AppError('SAVE_FAILED', 'Data save करने में fail हुआ', { cause: error });
}
Review Automation Script
// scripts/review-check.ts
import { execSync } from 'child_process';
interface ReviewIssue {
file: string;
line: number;
severity: 'error' | 'warning' | 'info';
message: string;
}
function checkForIssues(): ReviewIssue[] {
const issues: ReviewIssue[] = [];
const diff = execSync('git diff --cached --name-only').toString().split('\n');
for (const file of diff.filter(f => f.endsWith('.ts') || f.endsWith('.tsx'))) {
const content = execSync(`git show :${file}`).toString();
const lines = content.split('\n');
lines.forEach((line, index) => {
// console.log check
if (line.includes('console.log') && !file.includes('scripts/')) {
issues.push({
file, line: index + 1, severity: 'warning',
message: 'console.log बचा हुआ है',
});
}
// TODO/FIXME check
if (/\/\/\s*(TODO|FIXME|HACK)/i.test(line)) {
issues.push({
file, line: index + 1, severity: 'info',
message: 'TODO/FIXME comment है',
});
}
// any type check
if (/:\s*any\b/.test(line)) {
issues.push({
file, line: index + 1, severity: 'warning',
message: 'any type use हो रहा है',
});
}
});
}
return issues;
}
const issues = checkForIssues();
issues.forEach(i => console.log(`[${i.severity}] ${i.file}:${i.line} - ${i.message}`));
सारांश
Code review testing strategy से गहराई से जुड़ा है। Claude Code का उपयोग करके, security, performance, readability के दृष्टिकोण से systematic review efficiently किया जा सकता है। AI pair programming technique के साथ मिलाकर, review की quality और speed दोनों achieve कर सकते हैं। Code review best practices के लिए Google Engineering Practices देखें।
Related Posts
Claude Code से Productivity 3 गुना बढ़ाने की 10 Tips
Claude Code से ज़्यादा पाने की 10 practical tips जानें। Prompt strategies से workflow shortcuts तक, ये techniques आज से ही आपकी efficiency boost करेंगी।
Claude Code के साथ Canvas/WebGL Optimization
Claude Code का उपयोग करके Canvas/WebGL optimization के बारे में जानें। Practical tips और code examples शामिल हैं।
Claude Code के साथ Markdown Implementation
Claude Code का उपयोग करके markdown implementation सीखें। Practical tips और code examples शामिल हैं।