Kodlama Standartları
Genel Kurallar
| Kural | Değer |
|---|---|
| Max satır | 100 karakter |
| Indent | 2 space |
| Trailing comma | Kullan |
| Semicolon | Kullanma |
| Quote | Single ('') |
İsimlendirme
| Tür | Format | Örnek |
|---|---|---|
| Değişken | camelCase | userName |
| Fonksiyon | camelCase | getUserById |
| Sınıf | PascalCase | UserService |
| Constant | SCREAMING_SNAKE | MAX_RETRY |
| Dosya | kebab-case | user-service.ts |
| DB table | snake_case | user_profiles |
| API endpoint | kebab-case | /user-profiles |
Prensipler
- •✅ Açıklayıcı:
getUserByIdnotgetUser - •✅ Boolean:
is,has,canprefix - •✅ Array: çoğul
users,items - •❌ Kısaltma:
configurationnotcfg - •❌ Type prefix:
IUser
Fonksiyon Kuralları
- •Max satır: 20 (ideal: 10-15)
- •Max parametre: 3 (fazlaysa options object)
typescript
async function getUserById(userId: string): Promise<User | null> {
// 1. Early return / validation
if (!userId) {
throw new ValidationError('userId required')
}
// 2. Main logic
const user = await userRepository.findById(userId)
// 3. Return
return user
}
Error Handling
typescript
// ✅ Specific error, meaningful message
throw new ValidationError('Email format invalid', { field: 'email' })
// ✅ Error'ı yakala ve handle et
try {
await riskyOperation()
} catch (error) {
if (error instanceof ValidationError) {
// handle
} else {
logger.error('Unexpected', { error })
throw error
}
}
// ❌ Generic error
throw new Error('Error')
// ❌ Error yutma
try { ... } catch { /* sessiz */ }
Import Sırası
typescript
// 1. Built-in
import path from 'path'
// 2. External (alphabetical)
import express from 'express'
// 3. Internal (@/ paths)
import { UserService } from '@/services/user-service'
// 4. Relative
import { helper } from './helper'
// 5. Types
import type { User } from '@/types'
Code Smells
| Smell | Çözüm |
|---|---|
| Magic numbers | Constant kullan |
| Deep nesting (3+) | Early return, extract function |
| Long function (30+) | Böl |
| Long param list (4+) | Options object |
| Duplicate code | Extract function |
Edit/str_replace Best Practices
Anthropic SWE-Bench araştırmasına göre, doğru edit stratejisi başarı oranını önemli ölçüde artırır.
Temel Kurallar
| Kural | Açıklama |
|---|---|
| Absolute path | Her zaman tam yol kullan |
| Unique context | old_str en az 5 satır context içermeli |
| One change at a time | Büyük değişiklikleri parçala |
| Verify after | Edit sonrası dosyayı oku ve doğrula |
str_replace Stratejisi
typescript
// ✅ DOĞRU: Yeterli context ile unique match
old_str: `
async function getUserById(userId: string) {
if (!userId) {
throw new Error('userId required')
}
return await db.users.findById(userId)
}
`
// ❌ YANLIŞ: Çok kısa, unique olmayabilir
old_str: `return await db.users.findById(userId)`
Hata Durumunda
code
Hata: "old_str not found" veya "multiple matches" 1. Dosyayı oku → mevcut içeriği gör 2. Daha geniş context ekle (±3 satır) 3. Whitespace'leri kontrol et (tab vs space) 4. Tekrar dene
Edit Sırası
- •Önce oku → Dosyanın mevcut halini anla
- •Küçük parçalar → Tek seferde 20 satırdan fazla değiştirme
- •Doğrula → Her edit sonrası oku
- •Lint kontrol → Syntax hatası olmadığından emin ol
Commit Messages
code
<type>(<scope>): <description> [body] [footer]
| Type | Kullanım |
|---|---|
| feat | Yeni özellik |
| fix | Bug fix |
| docs | Dokümantasyon |
| refactor | Refactoring |
| test | Test |
| chore | Build, config |