AgentSkillsCN

coding-standards

我们项目的编码标准。在编写代码或进行代码评审时,自动应用这些标准。

SKILL.md
--- frontmatter
name: coding-standards
description: "Projemizin kodlama standartları. KOD YAZARKEN veya CODE REVIEW yaparken otomatik uygula."
allowed-tools:
  - Read
  - Grep
  - Glob
  - Edit
  - Write

Kodlama Standartları

Genel Kurallar

KuralDeğer
Max satır100 karakter
Indent2 space
Trailing commaKullan
SemicolonKullanma
QuoteSingle ('')

İsimlendirme

TürFormatÖrnek
DeğişkencamelCaseuserName
FonksiyoncamelCasegetUserById
SınıfPascalCaseUserService
ConstantSCREAMING_SNAKEMAX_RETRY
Dosyakebab-caseuser-service.ts
DB tablesnake_caseuser_profiles
API endpointkebab-case/user-profiles

Prensipler

  • ✅ Açıklayıcı: getUserById not getUser
  • ✅ Boolean: is, has, can prefix
  • ✅ Array: çoğul users, items
  • ❌ Kısaltma: configuration not cfg
  • ❌ 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 numbersConstant kullan
Deep nesting (3+)Early return, extract function
Long function (30+)Böl
Long param list (4+)Options object
Duplicate codeExtract 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

KuralAçıklama
Absolute pathHer zaman tam yol kullan
Unique contextold_str en az 5 satır context içermeli
One change at a timeBüyük değişiklikleri parçala
Verify afterEdit 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ı

  1. Önce oku → Dosyanın mevcut halini anla
  2. Küçük parçalar → Tek seferde 20 satırdan fazla değiştirme
  3. Doğrula → Her edit sonrası oku
  4. Lint kontrol → Syntax hatası olmadığından emin ol

Commit Messages

code
<type>(<scope>): <description>

[body]
[footer]
TypeKullanım
featYeni özellik
fixBug fix
docsDokümantasyon
refactorRefactoring
testTest
choreBuild, config