$npx -y skills add vibeeval/vibecosystem --skill coding-standardsUniversal coding standards - naming, formatting, error handling, immutability, SOLID principles
| 1 | # Coding Standards |
| 2 | |
| 3 | ## Naming Conventions |
| 4 | |
| 5 | | Tip | Format | Ornek | |
| 6 | |-----|--------|-------| |
| 7 | | Variable | camelCase | `userName`, `itemCount` | |
| 8 | | Function | camelCase, verb-first | `getUserById`, `calculateTotal` | |
| 9 | | Class/Type | PascalCase | `UserService`, `OrderItem` | |
| 10 | | Constant | UPPER_SNAKE | `MAX_RETRIES`, `API_URL` | |
| 11 | | File | kebab-case | `user-service.ts`, `order-item.ts` | |
| 12 | | Boolean | is/has/should prefix | `isActive`, `hasPermission` | |
| 13 | |
| 14 | ## Immutability |
| 15 | |
| 16 | ```typescript |
| 17 | // YANLIS: Mutate |
| 18 | user.name = newName; |
| 19 | items.push(newItem); |
| 20 | |
| 21 | // DOGRU: Yeni obje |
| 22 | const updated = { ...user, name: newName }; |
| 23 | const newItems = [...items, newItem]; |
| 24 | ``` |
| 25 | |
| 26 | ## Error Handling |
| 27 | |
| 28 | ```typescript |
| 29 | // Custom error class |
| 30 | class AppError extends Error { |
| 31 | constructor(public code: string, message: string, public statusCode = 500) { |
| 32 | super(message); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // Try-catch with specific errors |
| 37 | try { |
| 38 | const result = await riskyOperation(); |
| 39 | return result; |
| 40 | } catch (error) { |
| 41 | if (error instanceof ValidationError) { |
| 42 | throw new AppError('VALIDATION', error.message, 400); |
| 43 | } |
| 44 | throw new AppError('INTERNAL', 'Unexpected error', 500); |
| 45 | } |
| 46 | ``` |
| 47 | |
| 48 | ## Function Rules |
| 49 | |
| 50 | - Max 50 satir, tek sorumluluk |
| 51 | - Max 3 parametre (fazlasi obje olarak) |
| 52 | - Early return (nested if yerine guard clause) |
| 53 | - Pure function tercih et (side effect yok) |
| 54 | |
| 55 | ```typescript |
| 56 | // YANLIS: Deep nesting |
| 57 | function process(user) { |
| 58 | if (user) { |
| 59 | if (user.isActive) { |
| 60 | if (user.hasPermission) { |
| 61 | return doWork(user); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // DOGRU: Early return |
| 68 | function process(user) { |
| 69 | if (!user) return null; |
| 70 | if (!user.isActive) return null; |
| 71 | if (!user.hasPermission) return null; |
| 72 | return doWork(user); |
| 73 | } |
| 74 | ``` |
| 75 | |
| 76 | ## SOLID Principles |
| 77 | |
| 78 | | Prensip | Kural | |
| 79 | |---------|-------| |
| 80 | | S - Single Responsibility | Her sinif/fonksiyon tek is | |
| 81 | | O - Open/Closed | Extension'a acik, modification'a kapali | |
| 82 | | L - Liskov Substitution | Alt tip, ust tipin yerine gecebilmeli | |
| 83 | | I - Interface Segregation | Kucuk, specific interface'ler | |
| 84 | | D - Dependency Inversion | Abstraction'a baglan, concrete'e degil | |
| 85 | |
| 86 | ## Result<T,E> Pattern (Functional Error Handling) |
| 87 | |
| 88 | Exception fırlatmak yerine explicit error dondur. Ozellikle API katmaninda, service'lerde ve veri islemede kullan. |
| 89 | |
| 90 | ```typescript |
| 91 | // Result type tanimi |
| 92 | type Result<T, E = Error> = |
| 93 | | { ok: true; value: T } |
| 94 | | { ok: false; error: E }; |
| 95 | |
| 96 | // Kullanim |
| 97 | function parseConfig(raw: string): Result<Config, ValidationError> { |
| 98 | try { |
| 99 | const parsed = JSON.parse(raw); |
| 100 | if (!isValidConfig(parsed)) { |
| 101 | return { ok: false, error: new ValidationError('Invalid config shape') }; |
| 102 | } |
| 103 | return { ok: true, value: parsed as Config }; |
| 104 | } catch { |
| 105 | return { ok: false, error: new ValidationError('Invalid JSON') }; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Tuketim |
| 110 | const result = parseConfig(input); |
| 111 | if (!result.ok) { |
| 112 | logger.warn('Config parse failed', { error: result.error.message }); |
| 113 | return fallbackConfig; |
| 114 | } |
| 115 | const config = result.value; |
| 116 | ``` |
| 117 | |
| 118 | **Ne zaman kullan**: Service layer, parser, validator, external API cagrisi |
| 119 | **Ne zaman kullanma**: Basit utility, internal fonksiyon (try/catch yeterli) |
| 120 | |
| 121 | ## Comment Rules |
| 122 | |
| 123 | - **Yorumlar zamansiz olmali**: "Simdi boyle cunku..." yerine "Bu yaklasim X sebebiyle tercih edildi" yaz |
| 124 | - **Neden > Ne**: Kod ne yaptigini zaten gosteriyor, NEDEN yaptigini yaz |
| 125 | - **Clarity over brevity**: Kisa yorum ama anlamsizsa, uzun ama anlamli yorum yaz |
| 126 | - **Yanlis yorum > yorum yok**: Yanlis yorum tehlikelidir, guncellenmeyen yorum sil |
| 127 | |
| 128 | ```typescript |
| 129 | // YANLIS: Ne yaptigini anlatiyor (gereksiz) |
| 130 | // Kullanici adini buyuk harfe cevir |
| 131 | const name = user.name.toUpperCase(); |
| 132 | |
| 133 | // DOGRU: Neden yapildigini anlatiyor |
| 134 | // Legacy API buyuk harf bekliyor, v3'te kaldirilacak |
| 135 | const name = user.name.toUpperCase(); |
| 136 | ``` |
| 137 | |
| 138 | ## function vs Arrow Function |
| 139 | |
| 140 | | Durum | Tercih | Neden | |
| 141 | |-------|--------|-------| |
| 142 | | Exported fonksiyon | `function` declaration | Hoisted, debug stack trace'de gorunur | |
| 143 | | React component | `function` declaration | Tutarlilik, DevTools'da isim gorunur | |
| 144 | | Callback, inline | Arrow `=>` | Kisa, this binding yok | |
| 145 | | Method | Arrow (class field) | this binding garantili | |
| 146 | |
| 147 | ```typescript |
| 148 | // DOGRU: Exported fonksiyon |
| 149 | export function calculateTotal(items: Item[]): number { |
| 150 | return items.reduce((sum, item) => sum + item.price, 0); |
| 151 | } |
| 152 | |
| 153 | // DOGRU: Callback |
| 154 | const filtered = items.filter(item => item.active); |
| 155 | ``` |
| 156 | |
| 157 | ## Anti-Patterns |
| 158 | |
| 159 | | Anti-Pattern | Cozum | |
| 160 | |-------------|-------| |
| 161 | | Magic number | Named constant kullan | |
| 162 | | God class/function | Parcala, tek sorumluluk | |
| 163 | | console.log debug | Logger kullan, commit etme | |
| 164 | | Hardcoded values | Config/env variable | |
| 165 | | Any type | Specific type tanimla | |