Skip to content

Output-Formate

console, json, sarif und github-annotations.

codecharter analyze unterstützt vier Output-Formate via --output <format>. Das Flag ist wiederholbar und akzeptiert ein optionales Ziel als format:path, sodass eine einzige Analyse mehrere Formate gleichzeitig erzeugen kann. Siehe Mehrere Outputs in einem Lauf.

console (Default)

Menschenlesbarer Konsolen-Output mit ANSI-Farben. Findings werden nach Severity gruppiert, am Ende steht eine Zusammenfassung mit Anzahl der Violations, analysierten Typen und Methoden sowie der Dauer.

  --- Warning (1) ---

  WARN   [Testability] Direct DateTime/DateTimeOffset usage instead of TimeProvider
        PricingEngine.CalculatePrice
        src/Domain/PricingEngine.cs:42
        ↳ Inject TimeProvider via constructor and call GetUtcNow()

────────────────────────────────────────
  1 violation (1 warning)
  Analyzed 120 types, 840 methods in 3.2s

Farben sind standardmäßig aktiv, auch wenn der Output in eine Pipe oder Datei umgeleitet wird. Abschalten mit --no-color.

json

Strukturiertes JSON mit einem summary-Objekt (Anzahl der Violations, analysierte Typen und Methoden, Dauer) und einem violations-Array.

codecharter analyze MySolution.sln --output json --output-file findings.json

Ohne --output-file (bzw. ohne ein json:<path>-Ziel) wird das JSON nach stdout geschrieben, praktisch zum Weiterleiten an Tools wie jq.

Gut für Skript-Verarbeitung und eigene Auswertungen.

sarif

SARIF v2.1, Standard für statische Analyse-Tools, von GitHub Code Scanning, GitLab SAST und vielen IDEs direkt konsumierbar. Die Severity Info wird auf das SARIF-Level note abgebildet. Jedes Ergebnis trägt einen stabilen Fingerprint, sodass GitHub Code Scanning Findings über mehrere Läufe hinweg nachverfolgen kann.

codecharter analyze MySolution.sln --output sarif --output-file codecharter.sarif

Beispiel-Upload zu GitHub Code Scanning:

- name: Analyze
  run: codecharter analyze MySolution.sln --output sarif --output-file codecharter.sarif

- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: codecharter.sarif

github-annotations

GitHub-Workflow-Commands. Die GitHub Actions Runner verstehen das direkt und rendern Findings als Annotations an den betroffenen Zeilen in der "Files changed"-Ansicht des Pull Requests.

codecharter analyze MySolution.sln --output github-annotations

Der Output sieht so aus: Die Severity bestimmt das Command (Error wird zu ::error, Warning zu ::warning, Info zu ::notice), der Regelname landet in title=, die Message besteht aus der betroffenen Entität plus der Empfehlung.

::warning file=src/Domain/PricingEngine.cs,line=42,col=18,title=Direct DateTime/DateTimeOffset usage instead of TimeProvider::PricingEngine.CalculatePrice — Inject TimeProvider via constructor and call GetUtcNow()
::error file=src/Web/Controllers/ProductsController.cs,line=88,title=Async method without CancellationToken::ProductsController.GetProducts — ...

Eine einzeilige Zusammenfassung (CodeCharter: N violation(s) ...) geht nach stderr, sodass stdout ausschließlich die Workflow-Commands enthält.

Mit --workspace-root entfernen Sie ein Pfad-Präfix, falls die Solution in einem Unterverzeichnis des Workspaces liegt.

Die offizielle GitHub Action ruft die CLI mit diesem Format auf.

Mehrere Outputs in einem Lauf

--output ist wiederholbar und akzeptiert ein optionales Ziel als format:path. So erzeugt eine einzige Analyse mehrere Formate gleichzeitig, ohne zweiten Lauf:

codecharter analyze MySolution.sln \
  --output github-annotations \
  --output json:codecharter.json \
  --output sarif:codecharter.sarif

Regeln:

  • stdout-Formate (console, github-annotations) nehmen keinen Pfad und schreiben nach stdout; höchstens ein stdout-Format pro Lauf.
  • Datei-Formate (json, sarif) brauchen einen Pfad, wenn sie kombiniert werden.
  • Die Einzel-Output-Form bleibt unverändert: --output <format> (nach stdout) und --output <format> --output-file <path> funktionieren weiter. --output-file gilt nur für die Einzel-Output-Form und lässt sich nicht mit der format:path-Syntax mischen.
  • Eine ungültige Kombination (unbekanntes Format, fehlender Pfad bei einem kombinierten Datei-Format, --output-file gemischt mit format:path) beendet den Lauf mit Exit-Code 2 und einer Usage-Fehlermeldung.

Welches Format wann

Szenario Format
Lokal in der Konsole console
GitHub Actions PR-Annotations github-annotations
GitHub Code Scanning Security-Tab sarif
GitLab SAST sarif
Eigenes Dashboard oder Skript json
Archivieren als CI-Artifact json oder sarif