Kod Kalitesi

Denomas kod kalitesi standartları — linter, pre-commit hooks, kalite kapıları, SAST, semantic versioning

Kod Kalitesi

Denomas'ta kod kalitesi, geliştirme sürecinin ayrılmaz bir parçasıdır. Her commit, pre-commit hook'larından geçer; her MR, Otomatik Kalite Kapısından geçmek zorundadır. Bu kapı, bilinen güvenlik açıklarının (SQL injection, XSS vb.) koda girmesini en başından engeller.

Temel Kural

Pre-commit Hooks

Tüm projelerde aşağıdaki pre-commit hook'ları aktiftir:

# .pre-commit-config.yaml
repos:
  # Genel dosya kontrolleri
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
        args: ['--allow-multiple-documents']
      - id: check-json
      - id: check-merge-conflict
      - id: detect-private-key
      - id: check-added-large-files
        args: ['--maxkb=1024']
      - id: no-commit-to-branch
        args: ['--branch', 'main', '--branch', 'master']

  # Python: Ruff (flake8 + isort + pyupgrade birleşimi)
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.4.0
    hooks:
      - id: ruff
        args: ['--fix']
      - id: ruff-format

  # Python: Black (formatter)
  - repo: https://github.com/psf/black
    rev: 24.4.0
    hooks:
      - id: black
        args: ['--line-length=120']

  # Python: MyPy (tip kontrolü)
  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.10.0
    hooks:
      - id: mypy
        additional_dependencies: ['types-requests', 'types-redis']
        args: ['--ignore-missing-imports']

  # Python: Bandit (güvenlik taraması)
  - repo: https://github.com/PyCQA/bandit
    rev: 1.7.8
    hooks:
      - id: bandit
        args: ['-c', 'pyproject.toml', '-r']
        additional_dependencies: ['bandit[toml]']

  # Ansible
  - repo: https://github.com/ansible/ansible-lint
    rev: v24.2.0
    hooks:
      - id: ansible-lint

  # Docker
  - repo: https://github.com/hadolint/hadolint
    rev: v2.12.0
    hooks:
      - id: hadolint

  # Shell
  - repo: https://github.com/shellcheck-py/shellcheck-py
    rev: v0.10.0
    hooks:
      - id: shellcheck

  # Commit message format (Conventional Commits)
  - repo: https://github.com/compilerla/conventional-pre-commit
    rev: v3.2.0
    hooks:
      - id: conventional-pre-commit
        stages: [commit-msg]
        args: ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'ci']

Linter Yapısı

Dil/FormatLinterFormatterKonfigürasyon Dosyası
Pythonruff (flake8 + isort + pyupgrade)black (line-length: 120)pyproject.toml
Python (Tip)mypy (strict mode)-pyproject.toml
JavaScript/TypeScriptESLint (airbnb-base preset)Prettier.eslintrc.js, .prettierrc
YAMLyamllint-.yamllint.yml
Ansibleansible-lint-.ansible-lint
Dockerfilehadolint-.hadolint.yaml
Shellshellcheckshfmt-
Markdownmarkdownlint-.markdownlint.json
Odoo XMLodoo-lint (özel)-pyproject.toml

Python Konfigürasyon Örneği (pyproject.toml)

[tool.ruff]
line-length = 120
target-version = "py310"

[tool.ruff.lint]
select = ["E", "F", "W", "I", "N", "UP", "S", "B", "A", "C4", "DTZ", "T20", "ICN"]
ignore = ["E501"]  # Line length ruff-format tarafından yönetilir

[tool.black]
line-length = 120
target-version = ['py310']

[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true

[tool.bandit]
exclude_dirs = ["tests", "migrations"]
skips = ["B101"]  # assert kullanımına izin ver (test dosyalarında)

[tool.pytest.ini_options]
minversion = "7.0"
addopts = "--cov=src --cov-report=xml --cov-report=term --cov-fail-under=80"
testpaths = ["tests"]

Kalite Kapıları (Quality Gates)

CI/CD pipeline'da şu kalite kapıları zorunludur (CI/CD Pipeline sayfasında detaylı anlatım):

KapıKoşulBloklar Mı?Aşama
Pre-commitTüm hook'lar geçmeliEvet — commit reddedilirLokal
Ruff LintSıfır hataEvet — pipeline başarısızlint
MyPyTip hataları sıfırEvet — pipeline başarısızlint
ESLintSıfır hata (uyarılar kabul edilir)Evetlint
Unit Test%80+ kapsamEvettest
Entegrasyon TestTüm testler geçmeliEvettest
SAST (Bandit)Kritik/yüksek bulgu yokEvetscan
SAST (Semgrep)Kritik/yüksek bulgu yokEvetscan
GitLab SASTDahili tarayıcı temizEvetscan
Dependency Scan (Trivy)Bilinen CVE yok (kritik/yüksek)Evetscan
Container ScanDocker image'da kritik CVE yokEvetscan
DocstringPublic fonksiyonlarda docstring zorunluEvetlint
License CheckUyumsuz lisans yok (GPL kontrol)Evetscan
Conventional CommitsCommit mesajı formatı uyumluEvetLokal

SAST (Static Application Security Testing)

Her MR'da aşağıdaki güvenlik tarayıcıları otomatik çalışır:

AraçKapsamKonfigürasyon
BanditPython güvenlik açıkları (SQL injection, hardcoded passwords, unsafe deserialization)pyproject.toml [tool.bandit]
SemgrepÇoklu dil desteği, özel kural setleri.semgrep.yml + p/owasp-top-ten ruleset
GitLab SASTDahili tarayıcı (tüm desteklenen diller).gitlab-ci.yml include template
TrivyContainer image ve dependency taramasıCI/CD pipeline içinde

Docstring Zorunluluğu

Tüm public fonksiyonlar, sınıflar ve modüller Google-style docstring içermelidir:

def calculate_sla_compliance(incidents: list[dict], period: str) -> float:
    """SLA uyumluluk oranını hesaplar.

    Args:
        incidents: Olay listesi. Her eleman {"timestamp": str, "severity": int,
            "resolved_at": str} anahtarlarını içermelidir.
        period: Hesaplama dönemi. Geçerli değerler: "daily", "weekly", "monthly".

    Returns:
        SLA uyumluluk yüzdesi (0.0 - 100.0).

    Raises:
        ValueError: Geçersiz period değeri için.

    Example:
        >>> incidents = [{"timestamp": "2026-01-01", "severity": 2, "resolved_at": "2026-01-01"}]
        >>> calculate_sla_compliance(incidents, "monthly")
        99.5
    """
    ...

Odoo Modülü Docstring Standardı

class IlimEkosistemBase(models.Model):
    """İlim Teknoloji ekosistem base modülü.

    Bu modül, tüm İlim Teknoloji özel modüllerinin miras aldığı
    temel iş mantığını ve ortak alanları içerir.

    Attributes:
        _name: Odoo model ismi.
        _description: Kullanıcıya görünen model açıklaması.
        x_service_category: Tüm otomasyon mantığını yönlendiren ana anahtar.
        x_provisioning_type: Hangi provizyon iş akışının tetikleneceğini belirler.
    """
    _name = 'ilim.ekosistem.base'
    _description = 'Ilim Ekosistem Base'

    x_service_category = fields.Selection([...], string="Hizmet Kategorisi")
    x_provisioning_type = fields.Selection([...], string="Provizyon Tipi")

Semantic Versioning

Tüm projeler SemVer 2.0 kullanır:

MAJOR.MINOR.PATCH[-pre.N]
DeğişiklikVersiyon ArtışıÖrnek
Geriye uyumsuz API değişikliğiMAJOR2.0.0 → 3.0.0
Yeni özellik (geriye uyumlu)MINOR2.1.0 → 2.2.0
Bug fixPATCH2.1.1 → 2.1.2
Release candidatePre-release2.2.0-rc.1
BetaPre-release3.0.0-beta.1

Commit Mesajı Formatı (Conventional Commits)

<tip>(<kapsam>): <açıklama>

[opsiyonel gövde]

[opsiyonel alt bilgi]

Tip'ler: feat, fix, docs, style, refactor, test, chore, ci

Örnekler:

feat(monitoring): Zabbix 7.x için yeni SNMP v3 template eklendi
fix(api): Rate limiter yanlış HTTP status kodu döndürüyordu (#1234)
docs(handbook): ürünleşme yaklaşımı metodolojisi sayfası güncellendi
chore(deps): PostgreSQL driver 3.1.18'e yükseltildi

İlgili Sayfalar