Skip to content

feat(metrics): Stylistic-Drift innerhalb File (Block weicht vom File-Profil ab) #54

Description

@aspala

Was & Warum

Misst, ob ein einzelner Block stilistisch aus dem Rest des Files herausfällt — z.B. saubere kleine Funktionen, dann ein reingeklatschter God-Block. Niedrig = homogen geschrieben, hoch = Stilbruch (oft reingepasteter Fremdcode).

Skala

Verhalten Beispiel erwarteter Drift
niedrig (homogen) alle Funktionen gleich strukturiert ~0
mittel eine Funktion etwas dichter gering
hoch (Drift) saubere Funktionen + ein verschachtelter Monster-Block hoch

Umsetzung

  • Neues Modul lib/codeqa/metrics/file/stylistic_drift.ex, @behaviour CodeQA.Metrics.File.FileMetric.
  • Input: Block-Struktur über den Parser (ctx.blocks bzw. Parser.detect_blocks/2, wie Menzerath und NearDuplicateBlocksFile es nutzen). Pro Block ein Stil-Vektor (Token-Density, Verschachtelungstiefe, Keyword-Mix) → Distanz jedes Blocks zum File-Mittelprofil.
  • keys: ["max_block_drift", "mean_block_drift", "drifting_block_count"].
  • Registrieren in lib/codeqa/engine/analyzer.ex.
  • Edge-Cases: 0–1 Block → kein Drift berechenbar.

Test

  • test/codeqa/metrics/file/stylistic_drift_test.exs, Muster wie brevity_test.exs.
  • Assertion: File aus gleichförmigen Funktionen → max_block_drift ≈ 0; gleichförmige Funktionen + ein tief verschachtelter God-Block → hoher max_block_drift.

Hinweis

Nutzt denselben Block-Parser wie #45-Erweiterungen denkbar. Setzt auf vorhandene Block-Erkennung (Menzerath, near_duplicate_blocks) — kein neuer Parser nötig.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions