Add SARIF (Static Analysis Results Interchange Format) output support
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Feature
Add support for SARIF (Static Analysis Results Interchange Format) output format to mypy, similar to the existing --output=json option.
Pitch
SARIF is an OASIS standard format for static analysis results that is widely supported by modern CI/CD platforms and security tools:
- GitHub Advanced Security natively ingests SARIF files for code scanning alerts
- Azure DevOps supports SARIF for displaying security and code quality results
- GitLab can process SARIF reports for vulnerability tracking
- Many other security and code quality platforms (SonarQube, CodeQL, etc.) support SARIF
Other Python type checkers like Pyre already support SARIF output. Adding this to mypy would:
- Improve integration with GitHub/Azure/GitLab security features
- Make it easier to use mypy in enterprise CI/CD pipelines
- Provide a standardized foundation for richer diagnostics supported by SARIF
- Enable consumption by security tools that require standardized formats
Example Usage
# Generate SARIF output
mypy myproject/ --output=sarif > results.sarif
# Upload to GitHub Code Scanning (requires gzip + base64 encoding)
gzip -c results.sarif | base64 -w0 > results.sarif.gz.b64
gh api /repos/owner/repo/code-scanning/sarifs --method POST \
--field commit_sha="$(git rev-parse HEAD)" \
--field ref="refs/heads/main" \
--field sarif="@results.sarif.gz.b64"
Implementation Notes
The implementation could likely build on the existing output formatter infrastructure:
- Add a new
SARIFFormatterclass inmypy/error_formatter.pyextendingErrorFormatter - Add "sarif" to the
OUTPUT_CHOICESdictionary - Implement the SARIF v2.1.0 JSON schema
The MypyError class already provides the necessary diagnostic data (file path, line, column, error code, message, severity). Note that SARIF requires aggregating results into a single document structure rather than line-by-line output like JSON, which may require some adjustments to the formatter interface.
Related Issues
- #10816 (closed) - discussed multiple output formats including SARIF in comments
- #17612 - GitHub Actions workflow commands format (similar motivation)
- #20212 - Include summary in JSON output
References
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in mypy/error_formatter.py leggendo ErrorFormatter, MypyError, il percorso di output JSON esistente e OUTPUT_CHOICES. Esamina quindi la specifica SARIF v2.1.0 e determina come aggregare l'output del formatter in un unico documento. Il lavoro è completato quando mypy accetta --output=sarif ed emette un report compatibile con SARIF contenente i dati diagnostici disponibili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100